【发布时间】: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