ScriptIntrinsicBlur 生成不适当的模糊

ScriptIntrinsicBlur generates inappropriate blur

我一直在使用 ScriptIntrinsicBlur 模糊我的一张位图,它实际上填充了一种纯色。但是我得到的模糊效果真的不合适。请检查下图。白色部分实际上是我模糊的位图。位图实际上用纯色填充整个 window。

以下是模糊处理的代码。

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 像素的位图,它实际上填满了整个 window。我不知道我做错了什么。非常感谢您的帮助。

我认为你指的是调暗和模糊背景,而不仅仅是模糊纯色。

尝试按照本教程进行操作:http://allegro.tech/2015/08/android-fogger.html

或直接进入图书馆:https://github.com/allegro/fogger