How to write Image to ImageWriter in Android | Minhaz’s Blog
Android framework provides ImageWriter class as a way for applications to produce Image data int a Surface which can then be consumed by other components like CameraDevice. I found a couple of hiccups while trying to write jpeg images to ImageWriter buffers and found that there is scarce documentation around this out in the wild. In this article I’ll share briefly on how to write jpeg images or YUV images to ImageWriter in Android.
I've been struggling with this issue for quite a while.
I haven't found a device that will allow me to create a ImageWriter with ImageFormat.JPEG on a SurfaceView. I always get "Exception configuring surface"
The YuvImage class is a great way to convert YUV to JPEG. I'm using it with YUY2. No problems.
I have managed to get an ImageWriter to write YUV420 to a SurfaceView. The best way I have found to convert JPEG to YUV420 is to decode the JPEG with BitmapFactory, then process it with libyuv. Libyuv is stupid fast. The problem is figuring out which YUV420 variant the Image is using. Luckily, Android only supports NV21 and YV12. If your plane[1] pixelStride is 2, it's NV21 else it's YV12(I420 in libyuv)
You can also directly convert YUY2 to YUV420 with libyuv.
How to write Image to ImageWriter in Android | Minhaz’s Blog
Android framework provides ImageWriter class as a way for applications to produce Image data int a Surface which can then be consumed by other components like CameraDevice. I found a couple of hiccups while trying to write jpeg images to ImageWriter buffers and found that there is scarce documentation around this out in the wild. In this article I’ll share briefly on how to write jpeg images or YUV images to ImageWriter in Android.
https://blog.minhazav.dev/how-to-write-images-to-ImageWriter-in-Android/