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:
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):
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