Raaja SN Raaja SN - 1 month ago 17
Android Question

ScriptIntrinsicBlur generates inappropriate blur

I have been using ScriptIntrinsicBlur to blur one of my bitmap which actually filled with one SOLID COLOR. But the blur effect i get is really inapropriate. Kindly check the image below. The white portion is actually the bitmap i blurred. The bitmap actually fills the entire window with a solid color.

enter image description here

Below is may code for blurring.

static Bitmap blurBackground(Context context, int color, int width, int height){
Log.d("AppLock","RENDER DONE in " + System.currentTimeMillis());

Bitmap bitmap = Bitmap.createBitmap(200,200, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(color);
canvas.save();

Bitmap blurredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888,true);
RenderScript renderScript = RenderScript.create(context);

Allocation inputAllocation = Allocation.createFromBitmap(renderScript,blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL
, Allocation.USAGE_SHARED);
Allocation outputAllocation = Allocation.createTyped(renderScript,inputAllocation.getType());

ScriptIntrinsicBlur bluerScript = ScriptIntrinsicBlur.create(renderScript,Element.A_8(renderScript));
bluerScript.setInput(inputAllocation);
bluerScript.setRadius(15f);
bluerScript.forEach(outputAllocation);
outputAllocation.copyTo(blurredBitmap);
bitmap.recycle();
renderScript.destroy();
Log.d("AppLock","RENDER DONE in " + System.currentTimeMillis());
return blurredBitmap;

}


I have been following a tutorial from here Link To Tutorial

I have looked into numerous posts here and i am aware that i should use ARGB_8888 for render script. Also I tried changing the Element to Element.U8_4() . But what it does is just gives me back a Bitmap of 200x200 pixel and it actually fills the entire window. I don't know what am i doing wrong. Help would be highly appreciated.

Answer

I think what you are referring to is both Dimming and Blurring the background, not just blurring a solid color.

Try following this tutorial: http://allegro.tech/2015/08/android-fogger.html

or Jump right into the library: https://github.com/allegro/fogger

Comments