执行ScriptIntrinsicYuvToRgb [英] Executing ScriptIntrinsicYuvToRgb
问题描述
我想转换一个byte []在YUV成RGB一个byte []。该ScriptIntrinsic(ScriptIntrinsicYuvToRgb)应该做到这一点(在此基础上<一个href="https://android.googlesource.com/platform/frameworks/rs/+/master/java/tests/Live$p$pview/src/com/android/rs/live$p$pview/"相对=nofollow>例如)。
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.
这篇关于执行ScriptIntrinsicYuvToRgb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!