renderscript:非致命的rs错误,foreach内核索引超出界限

jc3wubiy  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(350)

我试图运行一个简单的renderscript示例,但出现以下错误:

01-03 16:10:04.723 25608-28248/com.testing.android E/RenderScript_jni: non fatal RS error, The forEach kernel index is out of bounds

导致此问题的代码是:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_img_name);

ScriptC_test test = new ScriptC_test(mRS);
Allocation in = Allocation.createFromBitmap(mRS, bitmap);
Allocation out = Allocation.createTyped(mRS, in.getType());

test.forEach_grayscale(in, out);
out.copyTo(bitmap);

我的rs文件如下所示:


# pragma version(1)

# pragma rs java_package_name(com.testing.android)

uchar4 RS_KERNEL grayscale(uchar4 pixelIn, uint32_t x, uint32_t y) {
    uchar grayscale = (pixelIn.r + pixelIn.g + pixelIn.b) / 3;  // simple average

    uchar4 pixelOut;
    pixelOut.a = pixelIn.a;
    pixelOut.r = grayscale;
    pixelOut.g = grayscale;
    pixelOut.b = grayscale;

    return pixelOut;
}

有人知道上面的代码有什么问题吗?
谢谢您!

dwthyt8l

dwthyt8l1#

我通过从支持库(android.support.v8.renderscript)切换到本机库(android.renderscript)解决了这个问题。
如果有人知道这有什么不同,请告诉我!

相关问题