Skip to content

Instantly share code, notes, and snippets.

@eliseomartelli
Created February 4, 2015 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliseomartelli/08659904a55f703fea99 to your computer and use it in GitHub Desktop.
Save eliseomartelli/08659904a55f703fea99 to your computer and use it in GitHub Desktop.
public Bitmap blur(Bitmap inBitmap, int radius) {
if (radius >= 25) {
radius = 25;
}
Bitmap bitmap = inBitmap.copy(inBitmap.getConfig(), true);
final RenderScript rs = RenderScript.create(getApplicationContext());
final Allocation input = Allocation.createFromBitmap( rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT );
final Allocation output = Allocation.createTyped( rs, input.getType() );
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create( rs, Element.U8_4(rs) );
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
return bitmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment