In my application, we need to display the Video frame receives from server to our android application,
Server is sending video data @ 50 frame per second, having encoded
Another way would be using ScriptIntrinsicYuvToRGB, this is more efficient then encoding (and decoding) each time a JPEG
fun yuvByteArrayToBitmap(bytes: ByteArray, width: Int, height: Int): Bitmap {
val rs = RenderScript.create(this)
val yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));
val yuvType = Type.Builder(rs, Element.U8(rs)).setX(bytes.size);
val input = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);
val rgbaType = Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height);
val output = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);
input.copyFrom(bytes);
yuvToRgbIntrinsic.setInput(input);
yuvToRgbIntrinsic.forEach(output);
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
output.copyTo(bitmap)
input.destroy()
output.destroy()
yuvToRgbIntrinsic.destroy()
rs.destroy()
return bitmap
}