Skip to content

Instantly share code, notes, and snippets.

@blaswan
Created February 24, 2014 11:23
Show Gist options
  • Save blaswan/9186683 to your computer and use it in GitHub Desktop.
Save blaswan/9186683 to your computer and use it in GitHub Desktop.
getBlurredBitmap
public static Bitmap blur(Context context, Bitmap sentBitmap, int radius) {
if (VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, 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); //0.0f ~ 25.0f
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