【问题标题】:Executing ScriptIntrinsicYuvToRgb执行 ScriptIntrinsicYuvToRgb
【发布时间】:2013-08-26 02:09:00
【问题描述】:

我想将 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 中显示它)。但是位图显示为空白。这段代码 sn-p 有什么问题?

【问题讨论】:

    标签: android renderscript


    【解决方案1】:

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

    【讨论】:

    • 就是这样!我还必须删除 setSurface(null) 调用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    • 2016-05-10
    相关资源
    最近更新 更多