Created
June 1, 2016 08:38
-
-
Save MensObscura/9606fafcb75ca10ac4b2be4d68effe5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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