Android ScriptIntrinsicBlur 不会模糊整个图像并生成透明边缘

标签 android transparent blur renderscript artifact

我在使用 RenderScript ScriptIntrinsic Blur 时遇到一些问题 - 在某些设备上它不会模糊整个图像。我缩小输入图像并确保宽度是 4 的倍数(因为 Roman Nurik 建议:https://plus.google.com/+RomanNurik/posts/TLkVQC3M6jW)

@SuppressLint("NewApi")
private Bitmap blurRenderScript(Bitmap smallBitmap) {

    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(BLUR_RADIUS);
    script.setInput(inAlloc);
    script.forEach(outAlloc);
    outAlloc.copyTo(output);

    rs.destroy();

    MutableBitmap.delete(smallBitmap);

    return output;
}

它在 Nexus 4 上工作:

Nexus 4 before blurring Nexus 4 after blurring

但在 Galaxy S4 上,右侧有透明边缘:

Galaxy S4 before blurring Galaxy S4 after blurring

我希望你能明白我的意思 - 如果你在 gimp 中打开图片,你可以看得更清楚。这与图片大小无关。我还用更大和更小的图像尝试过,结果总是一样的。例如,它也发生在 Nexus 7 2012 上。此外,透明伪像有时位于底部或左侧边缘。预先感谢您的帮助!

Nexus 4:4.4.2/内部版本号 KOT49H Galaxy S4:4.2.2/内部版本号 JDQ39.I9505XXUDMGG

最佳答案

我不确定为什么这会起作用,但对我来说它确实..

尝试代替

    Bitmap output = Bitmap.createBitmap(smallBitmap.getWidth(), smallBitmap.getHeight(), smallBitmap.getConfig());

像这样传入Bitmap.Config.ARGB_8888

    Bitmap output = Bitmap.createBitmap(smallBitmap.getWidth(), smallBitmap.getHeight(), Bitmap.Config.ARGB_8888);

关于Android ScriptIntrinsicBlur 不会模糊整个图像并生成透明边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22374201/

相关文章:

android - Opencl 在 ARM 上找不到 gpu

javascript - 下载时如何在 NextJS 中呈现图像的模糊版本?

ios - 使用 CiGaussianBlur 模糊图像的 UISlider 也旋转图像

Android 模糊 mask 滤镜

Android NestedScrollView.smoothScrollBy() 滚动太远

android - 如何在 Android 上使用 RxJava (+ retrofit2) 执行 3 个以上的并行 http 请求

android - 这似乎不是 “Debug” 版本

android - 透明状态栏与操作栏重叠

html - 如何使用 CSS 在悬停时创建此透明图像叠加层?

c# - 当图片框位于另一个图像上方时如何使它透明