【问题标题】:Applying blur using RenderScript in Android creates weird output在 Android 中使用 RenderScript 应用模糊会产生奇怪的输出
【发布时间】:2014-07-19 17:34:27
【问题描述】:

我正在尝试使用 RenderScript 类对图像应用模糊。这是我使用的代码(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;

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

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

【问题讨论】:

  • 输入位图是什么格式?这几乎看起来好像输入是 16 位的。 RS 模糊仅支持每通道 8 位位图。
  • 有没有发现哪里出了问题? @deepCover

标签: java android renderscript


【解决方案1】:

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

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

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

总结:渲染脚本模糊时不要使用RGB_565,而是使用ARGB_8888。

【讨论】:

    猜你喜欢
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 2018-02-09
    • 2019-02-03
    • 2021-07-26
    • 1970-01-01
    相关资源
    最近更新 更多