I need to do a Blur effect on a background image. How can I do this?
I need to do a Blur effect on a background image. How can I do this?
Use the Android ScriptIntrinsicBlur class to create the blur effect in>:
Use example, adapted from this question from the SOen:
@SuppressLint("NewApi")
private Bitmap blurRenderScript(Bitmap smallBitmap, int blurRadius) {
Bitmap output = Bitmap.createBitmap(smallBitmap.getWidth(), smallBitmap.getHeight(), smallBitmap.getConfig());
RenderScript rs = RenderScript.create(getContext());
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation inAlloc = Allocation.createFromBitmap(rs, smallBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE);
Allocation outAlloc = Allocation.createFromBitmap(rs, output);
script.setRadius(blurRadius);
script.setInput(inAlloc);
script.forEach(outAlloc);
outAlloc.copyTo(output);
rs.destroy();
MutableBitmap.delete(smallBitmap);
return output;
}
I use a very simple library to make these effects.
To use it is very simple:
Add dependency:
dependencies {
compile 'jp.wasabeef:blurry:2.0.3'
}
After you have stashed the image, you define Blur, for example:
Blurry.with(this)
.radius(10)
.sampling(8)
.color(Color.argb(66, 255, 255, 0))
.async()
.animate(500)
.onto(sua_imagem);
I use this paste to blur the images
Hope it helps. in git itself comes explaining how to include the lib and how to run the cod, with few lines you blur in the images.