Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MensObscura/9606fafcb75ca10ac4b2be4d68effe5f to your computer and use it in GitHub Desktop.
Save MensObscura/9606fafcb75ca10ac4b2be4d68effe5f to your computer and use it in GitHub Desktop.
public static class BlurTransformation implements com.squareup.picasso.Transformation {
private final float radius;
private Context mContext;
// radius is corner radii in dp
public BlurTransformation(final float radius, Context context) {
this.radius = radius;
this.mContext = context;
}
@Override
public Bitmap transform(final Bitmap source) {
int width = Math.round(source.getWidth());
int height = Math.round(source.getHeight());
Bitmap inputBitmap = Bitmap.createScaledBitmap(source, width, height, true);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
RenderScript rs = RenderScript.create(mContext);
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(radius);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
@Override
public String key() {
return "blur" + Float.toString(radius);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment