在Android中使用RenderScript应用模糊会产生奇怪的输出



我试图使用RenderScript类对图像应用模糊。这是我使用的代码(在这里。图像为原始位图)

    Bitmap inputImage = this.image;
    int height = inputImage.getHeight();
    int width = inputImage.getWidth();
    Bitmap blurredImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputImage);
    Allocation tmpOut = Allocation.createFromBitmap(rs, blurredImage);
    theIntrinsic.setRadius(25.f);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(blurredImage);
    this.image = blurredImage;
    return true;

这是函数的输入和输出https://i.stack.imgur.com/2d9DU.jpg

由于某种原因,它似乎将图像加倍,然后只保留绿色通道或其他东西。摆弄周围的模糊半径不工作,我找不到任何错误与我的代码(这是从一个工作的例子复制)

我也有同样的错误,并找出了导致它的原因,我知道这是一个问题从2年前,但仍然为那些谁提出了同样的问题。

问题是我一直使用的图像是RGB_565格式的,因为Renderscript模糊没有从RGB_565图像中获得足够的规格,它的结果输出是这样的。

我使用UniversalImageLoader与RGB_565配置,以减少内存使用,并在必要时对下载的图像有模糊效果,当我删除该配置使用默认ARGB_8888格式,一切都很好!

总结:不要使用RGB_565,而有渲染脚本模糊,使用ARGB_8888代替

最新更新