Camerax Analyzer imageProxy to Bitmap conversion gives the greenish image.

52 views
Skip to first unread message

Ramesh Sambu

unread,
Jan 12, 2023, 5:25:32 AM1/12/23
to Android CameraX Discussion Group
I used the below code to convert the imageProxy.In production getting the greenish images for some devices.Please help me to do in the right direction and minimua

private fun imageProxyToBitmap(image: ImageProxy): Bitmap? {
val yBuffer = image.planes[0].buffer // Y
val vuBuffer = image.planes[2].buffer // VU
val ySize = yBuffer.remaining()
val vuSize = vuBuffer.remaining()
val nv21 = ByteArray(ySize + vuSize)
yBuffer.get(nv21, 0, ySize)
vuBuffer.get(nv21, ySize, vuSize)
val yuvImage = YuvImage(nv21, ImageFormat.NV21, image.width, image.height, null)
val out = ByteArrayOutputStream()
yuvImage.compressToJpeg(Rect(0, 0, yuvImage.width, yuvImage.height), 50, out)
val imageBytes = out.toByteArray()
return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)
}

Ramesh Sambu

unread,
Jan 12, 2023, 5:26:11 AM1/12/23
to Android CameraX Discussion Group, Ramesh Sambu
Screenshot 2023-01-12 at 3.54.51 PM.png

Output after conversion

Kailiang Chen

unread,
Jan 12, 2023, 12:36:48 PM1/12/23
to Android CameraX Discussion Group, ram...@goniyo.com
Hi,

Could you check on these devices, the image.width is equal to image.getPlanes()[0].getRowStride() or not? 
Otherwise, you need to use rowStride instead.

Best,
Kailiang

Kailiang Chen

unread,
Jan 12, 2023, 12:51:50 PM1/12/23
to Android CameraX Discussion Group, Kailiang Chen, ram...@goniyo.com

Kailiang Chen

unread,
Jan 12, 2023, 12:52:28 PM1/12/23
to Android CameraX Discussion Group, Kailiang Chen, ram...@goniyo.com
Reply all
Reply to author
Forward
0 new messages