How to use ScriptIntrinsicYuvToRGB (converting byte[] yuv to byte[] rgba)

前端 未结 5 770
清酒与你
清酒与你 2020-12-01 09:40

I have byte[] yuvByteArray (540x360 image captured from Camera.PreviewCallback.onPreviewFrame method and dumped into assets/yuv.bin fi

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 10:36

    yuv.bin file is definitely in NV21 format, as it captures here http://developer.android.com/reference/android/hardware/Camera.PreviewCallback.html#onPreviewFrame

    setYuvFormat method is from API level 18, I removed it

    So this code works fine:

    rs = RenderScript.create(this);
    yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));
    
    Type.Builder yuvType = new Type.Builder(rs, Element.U8(rs)).setX(yuvByteArray.length);
    Allocation in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);
    
    Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(W).setY(H);
    Allocation out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);
    
    in.copyFrom(yuvByteArray);
    
    yuvToRgbIntrinsic.setInput(in);
    yuvToRgbIntrinsic.forEach(out);
    

提交回复
热议问题