1

我正在尝试运行一个简单的 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;
}

有谁知道上面的代码可能有什么问题?

谢谢!

4

1 回答 1

0

我通过从支持库 (android.support.v8.renderscript) 切换到本机库 (android.renderscript) 解决了这个问题。

如果有人知道为什么这会有所不同,请告诉我!

于 2017-01-05T21:59:29.160 回答