执行ScriptIntrinsicYuvToRgbScriptIntrinsicYuvToRgb

由网友(落幕唯情)分享简介:我想转换一个byte []在YUV成RGB一个byte []。该ScriptIntrinsic(ScriptIntrinsicYuvToRgb)应该做到这一点(在此基础上例如)。I want to convert a byte[] in Yuv into a byte[] in Rgb. The ScriptIntr...

我想转换一个byte []在YUV成RGB一个byte []。该ScriptIntrinsic(ScriptIntrinsicYuvToRgb)应该做到这一点(在此基础上例如)。

I want to convert a byte[] in Yuv into a byte[] in Rgb. The ScriptIntrinsic (ScriptIntrinsicYuvToRgb) is supposed to do this (based on this example).

下面是一些code我现在:

Here's some code I have right now:

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的显示出来)。但是,位图显示空白。什么是wwrong与此code段?

By the end of this script, I expect bitmap to contain something (I'm displaying it in an ImageView). But the bitmap shows up blank. What's wwrong with this code snippet?

推荐答案

我认为这个问题是输出的分配与USAGE_IO_OUTPUT创建,但表面上是从来没有连接。我会尝试用(USAGE_SCRIPT&安培; USAGE_SHARED)。或者只使用默认值

I think the problem is the output allocation is created with USAGE_IO_OUTPUT but a surface is never attached. I would try with (USAGE_SCRIPT & USAGE_SHARED) or just use the defaults.

阅读全文

相关推荐

最新文章