简体   繁体   English

Android camera2 YUV 2048x1536 捕获的图像被拉伸(不是预览)

[英]Android camera2 YUV 2048x1536 image captured is stretched (not the preview)

I'm trying to capture a YUV image but is stretched.我正在尝试捕获 YUV 图像但被拉伸。 I'm using Android Camera2 following this https://github.com/googlearchive/android-Camera2Basic .我在https://github.com/googlearchive/android-Camera2Basic 之后使用 Android Camera2。 The Android SDK is 28. Android SDK 是 28。

I'm facing a weird behavior when I capture a camera frame in YUV 2048x1536 from the method setOnImageAvailableListener() using the ImageReader.当我使用 ImageReader 从方法 setOnImageAvailableListener() 捕获 YUV 2048x1536 中的相机帧时,我面临一个奇怪的行为。 The capture is stretched:捕获被拉伸:

YUV 2048x1536 stretched YUV 2048x1536 拉伸

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?要将图像转换为位图,我使用了如何将 android.media.Image 转换为位图对象? :

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

YUV 960x720 ok YUV 960x720 可以

I don't know why the capture in YUV 2048x1536 is stretched and in YUV 960x720 isn't it.我不知道为什么 YUV 2048x1536 中的捕获被拉伸,而 YUV 960x720 不是。 The only change is the resolution唯一的变化是分辨率

Thanks谢谢

Does the device actually list 2048x1536 as a supported size in its stream configuration map?设备是否在其流配置图中将 2048x1536 列为支持的大小? 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). (此外,看起来您正在捕获 JPEG 图像,而不是未压缩的 YUV,在这里不一定重要)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM