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

时间:2014-05-30 03:14:55

标签: java android renderscript

我尝试使用RenderScript类将模糊应用于图像。这是我使用的代码(其中this.image是原始的Bitmap)

    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;

这是函数的输入和输出 http://imgur.com/a/EWJv6

由于某种原因,它似乎使图像加倍,然后只保留绿色通道或其他东西。使用模糊半径摆弄不起作用,我无法找到我的代码有任何问题(从一个工作示例中复制过来)

1 个答案:

答案 0 :(得分:1)

我遇到了同样的错误并发现了导致它的原因,我知道它是2年前的一个问题,但仍然是那些提出同样问题的人。

问题是我一直使用的图像是RGB_565格式化的,因为Renderscript模糊不能从RGB_565图像获得足够的规格,所以结果输出就像这样。

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

总结:在使用renderscript模糊时不要使用RGB_565,而是使用ARGB_8888。