执行ScriptIntrinsicYuvToRgb

时间:2013-08-26 02:09:01

标签: android renderscript

我想将Yuv中的byte []转换为Rgb中的byte []。 ScriptIntrinsic(ScriptIntrinsicYuvToRgb)应该这样做(基于此example)。

这是我现在的一些代码:

byte[] imageData = ...gatheryuvbuffer...

Type.Builder tb = new Type.Builder(mRS, Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV));
tb.setX(outputWidth);
tb.setY(outputHeight);
tb.setMipmaps(false);
tb.setYuvFormat(ImageFormat.NV21);
Allocation ain = Allocation.createTyped(mRS, tb.create(), Allocation.USAGE_SCRIPT);
ain.copyFrom(imageData);

Type.Builder tb2 = new Type.Builder(mRS, Element.RGBA_8888(mRS));
tb2.setX(outputWidth);
tb2.setY(outputHeight);
tb2.setMipmaps(false);

// Allocation aOutBitmap = Allocation.createFromBitmap(mRS, bitmap);
Allocation aOut = Allocation.createTyped(mRS, tb2.create(), Allocation.USAGE_IO_OUTPUT);
aOut.setSurface(null);

mYuvToRgb.setInput(ain);
mYuvToRgb.forEach(aOut);

Bitmap bitmap = Bitmap.createBitmap(outputWidth, outputHeight, Bitmap.Config.ARGB_8888);
aOut.copyTo(bitmap);

到这个脚本结束时,我希望位图包含一些东西(我在ImageView中显示它)。但位图显示为空白。这个代码片段的错误是什么?

1 个答案:

答案 0 :(得分:3)

我认为问题是输出分配是使用USAGE_IO_OUTPUT创建的,但表面永远不会附加。我会尝试(USAGE_SCRIPT& USAGE_SHARED)或只使用默认值。