by
0
4
3,443
4
Top 1% !
Popular
Famous
Specified
Popularity: 3554th place
Created
Modified Jan 22, 2015

Published on:

No tags for this snippet yet.
LicenseMIT_X11
SourceGitHub

This is a Picasso transform that blurs and darkens an image.

This is a Picasso transform that blurs and darkens an image.: 
blur_darken_transform
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/311486/This-is-a-Picasso-transform-that-blurs-a?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
private final class BlurTransform implements Transformation { WeakReference<Context> context; public BlurTransform(Context context) { super(); this.context = new WeakReference<>(context); } @Override public Bitmap transform(Bitmap bitmap) { RenderScript rs = RenderScript.create(context.get()); Bitmap source = bitmap.copy(Bitmap.Config.ARGB_8888, true); if (source == null) { return null; } Allocation input = Allocation.createFromBitmap(rs, source, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(17); script.setInput(input); script.forEach(output); output.copyTo(source); // also darken the image Paint paint = new Paint(); ColorFilter filter = new LightingColorFilter(0xFF444444, 0x00000000); paint.setColorFilter(filter); Canvas canvas = new Canvas(source); canvas.drawBitmap(source, 0, 0, paint); bitmap.recycle(); return source; } @Override public String key() { return "blur"; } }
If you want to be updated about similar snippets, Sign in and follow our Channels