简体   繁体   English

Android Renderscript在nexus 7上创建分配会导致错误

[英]Android Renderscript create allocation on nexus 7 causes error

I trying to convert camera preview frame from YUV format to bitmap with following code: 我尝试使用以下代码将相机预览帧从YUV格式转换为位图:

    mYuvToRgbScript = ScriptIntrinsicYuvToRGB.create(mRs, Element.RGBA_8888(mRs));
    final Allocation allocationIn = Allocation.createSized(mRs, Element.U8(mRs),
            (mPreviewWidth * mPreviewHeight) + ((mPreviewHeight / 2) * (mPreviewWidth / 2) * 2));
    allocationIn.copyFrom(mPreviewFrame);

    final Bitmap previewBitmap = Bitmap.createBitmap(mPreviewWidth, mPreviewHeight, Bitmap.Config.ARGB_8888);
    final Allocation allocationOut = Allocation.createFromBitmap(mRs, previewBitmap);

    mYuvToRgbScript.setInput(allocationIn);
    mYuvToRgbScript.forEach(allocationOut);

    allocationIn.destroy();
    allocationOut.destroy();

    if (previewBitmap != null) {
        return previewBitmap;
    } else
        return null;

This code works ok on 2 phones with android 4.1, but on nexus 7(2013) with android 4.4.3 following lines appears on every preview frame: 这段代码可以在装有Android 4.1的2部手机上正常工作,但在具有Android 4.4.3的nexus 7(2013)上,每个预览框上都会显示以下行:

W/Adreno-RS﹕ <rsdVendorAllocationSetupTexture:647>: ERROR: Runtime texture creation failed err: -10 image: 0x0 alloc: 0xad720000
W/Adreno-RS﹕ <rsdVendorAllocationSetupTexture:649>: ERROR: Runtime texture creation failed type: 8 kind: 0 eleSize: 1

And no conversion occurs. 并且没有转换发生。 With some debugging i located line that causes this log messages: 通过一些调试,我找到了导致此日志消息的行:

    final Allocation allocationIn = Allocation.createSized(mRs, Element.U8(mRs),
            (mPreviewWidth * mPreviewHeight) + ((mPreviewHeight / 2) * (mPreviewWidth / 2) * 2));

Also i tried another allocationIn creation: 我也尝试了另一个分配

    final Type.Builder tb = new Type.Builder(mRs, Element.U8(mRs));
    tb.setX(mPreviewFrame.length);
    final Allocation allocationIn = Allocation.createTyped(mRs, tb.create(), Allocation.USAGE_SCRIPT);

but it causes the same error log lines and no conversion occurs. 但是它会导致相同的错误日志行,并且不会进行转换。 Any thoughts how to fix it? 有什么想法如何解决?

You are forgetting to copy the allocation back into your preview bitmap. 您忘记将分配复制回预览位图中。 After your call to forEach(), you should do: 在调用forEach()之后,您应该执行以下操作:

allocationOut.copyTo(previewBitmap);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM