2016-10-21 42 views
1

我一直在使用ScriptIntrinsicBlur来模糊其中一个实际填充了一个SOLID COLOR的位图。但是我得到的模糊效果真的不合适。请检查下面的图片。白色部分实际上是我模糊的位图。位图实际上用纯色填充整个窗口。ScriptIntrinsicBlur生成不适当的模糊

enter image description here

下面是可用于模糊编码。

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像素的位图,它实际上填满了整个窗口。我不知道我做错了什么。帮助将不胜感激。

+0

我不明白。如果你模糊纯色,你会得到纯色。什么意思?还是我误解了一些东西? –

+0

@Saehun肖恩哦,我真的不明白模糊如何工作。我想从链接中的图片获得类似的效果。 http://imgur.com/5hxYziV –

回答

1

我认为你所说的是调暗和模糊背景,而不是模糊一个纯色。

尝试下面这个教程:http://allegro.tech/2015/08/android-fogger.html

或跳转到正确的库:https://github.com/allegro/fogger

+0

感谢您的链接。这个对我来说很好看。 –

+0

抱歉没有把详细代码放在这里。我从来没有使用这个库,所以我不能告诉你这是如何工作的。很高兴这有助于。 如果你有时间,你是否可以好好地张贴你的代码作为答案,即使链接被破坏,SO有答案?良好的做法来回答,但我正在工作大声笑 –

+0

当然会发布一次完成。图书馆看起来不错,很好。感谢您的链接 –