我一直在使用ScriptIntrinsicBlur来模糊其中一个实际填充了一个SOLID COLOR的位图。但是我得到的模糊效果真的不合适。请检查下面的图片。白色部分实际上是我模糊的位图。位图实际上用纯色填充整个窗口。ScriptIntrinsicBlur生成不适当的模糊
下面是可用于模糊编码。
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;
}
我已经从这里Link To Tutorial
下面的教程我已经看过成无数的帖子在这里,我意识到,我应该使用ARGB_8888用于渲染脚本。另外我尝试将Element更改为Element.U8_4()。但它所做的只是给我一个200x200像素的位图,它实际上填满了整个窗口。我不知道我做错了什么。帮助将不胜感激。
我不明白。如果你模糊纯色,你会得到纯色。什么意思?还是我误解了一些东西? –
@Saehun肖恩哦,我真的不明白模糊如何工作。我想从链接中的图片获得类似的效果。 http://imgur.com/5hxYziV –