Using the ImageWriter with JPEG-Surface of a ImageReader

2020-03-26 android image media

If create an ImageWriter using the following snippet:

ImageReader reader = ImageReader.newInstance(256, 256, ImageFormat.JPEG, 1);
ImageWriter writer = ImageWriter.newInstance(reader.getSurface(), 1);

We will see an exception, that the format of the Surface is not supported.

E/SurfaceView: Exception configuring surface
    java.lang.UnsupportedOperationException: Invalid format specified 33
        at android.media.ImageUtils.getEstimatedNativeAllocBytes(ImageUtils.java:233)
        at android.media.ImageWriter.<init>(ImageWriter.java:210)
        at android.media.ImageWriter.newInstance(ImageWriter.java:132)

While creating the ImageReader with a different format like ImageFormat.RGB_565 will create the ImageWriter successfully. Is there any way to get a working ImageWriter with JPEG-Surfaces, or any other way to send images to the ImageReader?

Answers

Related