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

前端 未结 5 771
清酒与你
清酒与你 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:30

    Kotlin

            val rs = RenderScript.create(CONTEXT_HERE)
            val yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs))
    
            val yuvType = Type.Builder(rs, Element.U8(rs)).setX(byteArray.size)
            val inData = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT)
    
            val rgbaType = Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height)
            val outData = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT)
    
            inData.copyFrom(byteArray)
    
            yuvToRgbIntrinsic.setInput(inData)
            yuvToRgbIntrinsic.forEach(outData)
    
            val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
            outData.copyTo(bitmap)
    

提交回复
热议问题