简体   繁体   English

Android预览相机返回不完整的数据数组

[英]Android preview camera returning incomplete data array

I'm attempting to do some image processing on images returned by the Android preview camera via onPreviewFrame. 我正在尝试对Android预览相机通过onPreviewFrame返回的图像进行一些图像处理。 This was working fine at sizes up to 1080 by 720, but I attempted to increase resolution to 1920 by 1080. The result is that I end up with incomplete data, and attempting to process every pixel gives an ArrayIndexOutOfBounds exception. 在最大尺寸为1080 x 720的情况下,此方法可以正常工作,但是我尝试将分辨率提高到1920 x1080。结果是,我最终得到的数据不完整,并且尝试处理每个像素都会产生ArrayIndexOutOfBounds异常。

The data of a 1920 by 1080 image has 2073600 pixels, but it appears that the data[] returned by onPreviewFrame is always of size 1382400, regardless of image resolution. 1920 x 1080图像的数据具有2073600像素,但是看来onPreviewFrame返回的data []的大小始终为1382400,而与图像分辨率无关。

params.setPreviewSize(1920, 1080);

mCamera.setPreviewCallback(new Camera.PreviewCallback() {
        public synchronized void onPreviewFrame(byte[] data, Camera camera) {
            changeMag = 0;
            thisDiff = 0;
            diffPixels = 0;
            try {
                if (currentImage != null) {
                    lastImage = currentImage;
                }
                Log.e("CameraTest", "Incoming data array size is only " + data.length);
}

This logs "Incoming data array size is only 1382400" no matter what preview size I select. 无论我选择什么预览大小,此日志都会记录“传入数据数组大小仅为1382400”。

Given that 1920 by 1080 is supposedly a supported size, is there any way to get back that data via onPreviewFrame? 考虑到1920 x 1080应该是受支持的大小,是否可以通过onPreviewFrame取回该数据?

Apparently, 1920x1080 is not supported. 显然,不支持1920x1080。 If getSupportedPreviewSizes() list does include this resolution, this would not be the first time that a device report is incorrect. 如果getSupportedPreviewSizes()列表确实包含此分辨率,则这将不是设备报告第一次不正确。 For example, Galaxy Nexus claims to support QVGA (320x240) preview, but it cannot deliver such image. 例如,Galaxy Nexus声称支持QVGA(320x240)预览,但无法提供此类图像。 setPreviewSize() + setParameters() continue correctly, and even getPreviewSize() reports the expected value. setPreviewSize()+ setParameters()可以正确继续,甚至getPreviewSize()也会报告期望值。 But the preview callback returns an image in size same as the size before setting this resolution. 但是预览回调返回的图像大小与设置此分辨率之前的大小相同。

So, I would expect that you really receive a 1280x720 picture, and can do nothing about it. 因此,我希望您确实能收到1280x720的图片,并且对此无能为力。

Note that it may still be possible to record 1920x1080 video on this device: video recorder may use a special mechanism which involves hardware encoder and often sends the camera data to this encoder without copying it to user space. 请注意,仍然可以在此设备上录制1920x1080的视频:录像机可能会使用一种特殊的机制,该机制涉及硬件编码器,并且经常将摄像机数据发送到该编码器,而不将其复制到用户空间。

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

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