Skip to content

Instantly share code, notes, and snippets.

@Mariuxtheone
Created May 24, 2014 14:02
Show Gist options
  • Save Mariuxtheone/903c35b4927c0df18cf8 to your computer and use it in GitHub Desktop.
Save Mariuxtheone/903c35b4927c0df18cf8 to your computer and use it in GitHub Desktop.

Revisions

  1. Mariuxtheone created this gist May 24, 2014.
    35 changes: 35 additions & 0 deletions blurBitmap.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    public Bitmap blurBitmap(Bitmap bitmap){

    //Let's create an empty bitmap with the same size of the bitmap we want to blur
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);

    //Instantiate a new Renderscript
    RenderScript rs = RenderScript.create(getApplicationContext());

    //Create an Intrinsic Blur Script using the Renderscript
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));

    //Create the Allocations (in/out) with the Renderscript and the in/out bitmaps
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);

    //Set the radius of the blur
    blurScript.setRadius(25.f);

    //Perform the Renderscript
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);

    //Copy the final bitmap created by the out Allocation to the outBitmap
    allOut.copyTo(outBitmap);

    //recycle the original bitmap
    bitmap.recycle();

    //After finishing everything, we destroy the Renderscript.
    rs.destroy();

    return outBitmap;


    }