简体   繁体   English

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

[英]Applying blur using RenderScript in Android creates weird output

I'm attempting to apply a blur to an image using the RenderScript class. 我正在尝试使用RenderScript类将模糊应用于图像。 Here is the code I use (where this.image is the original Bitmap) 这是我使用的代码(其中this.image是原始位图)

    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;

This is the input and output from the function http://imgur.com/a/EWJv6 这是功能http://imgur.com/a/EWJv6的输入和输出

For some reason, it appears to double the image and then only keep the green channel or something. 由于某种原因,它看起来会使图像加倍,然后仅保留绿色通道或其他东西。 Fidling around with the blur radius doesn't work, and I can't find anything wrong with my code (which was copied from a working example) 迷离模糊半径是行不通的,而且我找不到我的代码有什么问题(从工作示例中复制)

I had the same error and found out what was causing it, i know it's a question from 2 years ago but still for the ones who come up with same problem. 我遇到了同样的错误,并找出了导致它的原因,我知道这是两年前的一个问题,但仍然是那些提出相同问题的人。

The problem was the images that i've been using is RGB_565 formatted and because Renderscript blurring is not getting enough specifications from RGB_565 images it results outputs be like this. 问题是我一直在使用的图像是RGB_565格式的,并且由于Renderscript模糊无法从RGB_565图像中获得足够的规格,因此输出结果是这样的。

I was using UniversalImageLoader with RGB_565 configuration to reduce memory usage and having blur effect when necessary on downloaded images, and when i remove that configuration to use as default ARGB_8888 format, everything was just fine! 我正在使用具有RGB_565配置的UniversalImageLoader来减少内存使用,并在必要时对下载的图像产生模糊效果,当我删除该配置以用作默认的ARGB_8888格式时,一切都很好!

Sum up: Don't use RGB_565 while having renderscript blur, use ARGB_8888 instead. 总结:不要在渲染脚本模糊时使用RGB_565,而应使用ARGB_8888。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM