0

I'm trying to capture a YUV image but is stretched. I'm using Android Camera2 following this https://github.com/googlearchive/android-Camera2Basic. The Android SDK is 28.

I'm facing a weird behavior when I capture a camera frame in YUV 2048x1536 from the method setOnImageAvailableListener() using the ImageReader. The capture is stretched:

YUV 2048x1536 stretched

What I do:

pictureImageReader.setOnImageAvailableListener(
            reader -> {
              Image image = reader.acquireLatestImage();
              if(image != null){
                ByteBuffer buffer = image.getPlanes()[0].getBuffer();
                byte[] bytes = new byte[buffer.capacity()];
                buffer.get(bytes);
                Bitmap bitmapImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, null);
                image.close();
              }
            }, mBackgroundHandler);

To convert image to bitmap I used this How to convert android.media.Image to bitmap object?:

Image image = reader.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
buffer.get(bytes);
Bitmap bitmapImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, null);

However if I change the resolution my capture is fine (YUV 960x720):

YUV 960x720 ok

I don’t know why the capture in YUV 2048x1536 is stretched and in YUV 960x720 isn’t it. The only change is the resolution

Thanks

j11john
  • 29
  • 1
  • 7

1 Answers1

0

Does the device actually list 2048x1536 as a supported size in its stream configuration map? Sometimes camera devices will accept a resolution they don't actually list, but then can't properly output it.

If that size is listed, then this may just be a bug on that device's camera implementation, unfortunately.

(Also, it looks like you're capturing JPEG images, not uncompressed YUV, not that it necessarily matters here).

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
  • Hi! the device list that resolution. I did map.getOutputSizes(ImageFormat.YUV_420_888) and prints 2048x1536. So do you say it's a device error? I mean if I try in another could work? – j11john Sep 24 '20 at 22:00