I'm using the CameraX plugin which gives me a android.media.Image when I take a picture. Now I want to send the image over a webcall as a byteArray. I found a function that will create the byteArray for me:
private suspend fun createBytesFromImage(input: Image): ByteArray {
return withContext(ioDispatcher) {
val buffer = input.planes[0].buffer
buffer.rewind()
val bytes = ByteArray(buffer.capacity())
buffer.get(bytes)
return@withContext bytes
}
}
The image is pretty large and I want to compress/downscale it so a save some bandwidth. How do I do this with a android.media.Image or byteArray?
(I know I can make a bitmap from the byteArray, compress/downscale the bitmap and make a new byteArray out of it but this seems wrong. I'm looking for another way, if that's possible)
Use instead .setTargetResolution(Size(1080,1920))
on ImageCapture.Builder
To calculate file size according to resolution you can use this tool
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With