【问题标题】:RenderScript: Using ScriptGroup for image process causes horizontal stripesRenderScript:使用 ScriptGroup 进行图像处理会导致水平条纹
【发布时间】:2014-03-20 07:03:44
【问题描述】:

问题描述:

我使用 RenderScrip 编写了一个简单的演示,用于图像处理。在我的演示中,当我使用单内核渲染脚本时,它工作正常。然而,当我使用脚本组连接两个 rs-kernal 执行时,我发现输出位图带有水平条纹。尤其是当您选择小尺寸的位图时。

当我使用单内核渲染脚本时的输出位图:

当我使用脚本组连接两个 rs-kernal 时的输出位图。请注意,这两个 rs-kernal 与我上面使用的相同:

代码:

我相信我在 rs-kernal 中的代码是正确的。否则,在使用单内核渲染脚本时,我无法正确输出图片。问题是关于脚本组的。

这里是一些关于如何在脚本组中连接 rs-kernals 的代码:

    Type.Builder tb = new Type.Builder(mRs, Element.RGBA_8888(mRs));
    tb.setX(baseBitmapWidth);// the size of bitmap never changes during the whole process
    tb.setY(baseBitmapHeight);
    Type t = tb.create();

    ScriptGroup.Builder b = new ScriptGroup.Builder(mRs);

    int i = 0;
    for (i = 0; i < mOps.size(); i++) {
        RSOp op = mOps.get(i);
        b.addKernel(op.rsGetKernalID());
    }

    for (i = 1; i < mOps.size(); i++) {
        b.addConnection(t, mOps.get(i - 1).rsGetKernalID(), mOps.get(i)
                .rsGetKernalID());
    }

    mScriptGroup = b.create();

下面是一些关于如何执行脚本组的代码:

    Bitmap preparedBitmap = baseBitmap.copy(baseBitmap.getConfig(), true);
    mInAllocation = Allocation.createFromBitmap(mRs, baseBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
    mOutAllocation = Allocation.createTyped(mRs, mInAllocation.getType());

    mScriptGroup.setInput(mOps.get(0).rsGetKernalID(), mInAllocation);
    mScriptGroup.setOutput(mOps.get(mOps.size() - 1).rsGetKernalID(),
            mOutAllocation);

    mScriptGroup.execute();

    mOutAllocation.copyTo(preparedBitmap);

【问题讨论】:

  • 你猜到这个了吗?
  • 没有。我只是使用了许多单内核渲染脚本。

标签: android bitmap renderscript


【解决方案1】:

找到了解决办法: 只是使用了许多单核渲染脚本。使用前一个脚本的输出位图作为后一个脚本的输入。

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 2015-03-26
    • 2011-06-14
    • 2022-01-25
    • 2017-11-25
    • 1970-01-01
    相关资源
    最近更新 更多