简体   繁体   English

在 Android Camera2 API 中。 我可以使用图像读取器 (YUV_420_888) 进行处理,使用另一个 (JPEG) 来捕获静止图像吗?

[英]In Android Camera2 API. Can I use a image reader (YUV_420_888) for processing and another(JPEG) for capture still image?

I try but preview freeze when I press the capture button and no image created.当我按下捕获按钮并且没有创建图像时,我尝试但预览冻结。 Any suggestion ?有什么建议吗? How many imagereader can I use in one Camera2 project?我可以在一个 Camera2 项目中使用多少个图像阅读器?

For every CaptureSession you are creating,you can only have one ImageReader.对于您创建的每个 CaptureSession,您只能拥有一个 ImageReader。 If you want to use two different ImageReader for each type of Image then you should use two CaptureSession.如果您想为每种类型的图像使用两个不同的 ImageReader,那么您应该使用两个 CaptureSession。 But you have to be very careful about the handling of camera resources between the two Sessions(ex. you should close ImageReader for JPEG before starting other CaptureSession for capturing YUV_420_888 image).但是您必须非常小心地处理两个会话之间的相机资源(例如,在启动其他 CaptureSession 以捕获 YUV_420_888 图像之前,您应该关闭 ImageReader for JPEG)。 Using multiple CaptureSession is also heavy on the device and generally not recommended.在设备上使用多个 CaptureSession 也很重,通常不推荐。 Instead you can use same bytes for both type of image.相反,您可以对两种类型的图像使用相同的字节。

public void onImageAvailable(ImageReader imageReader) {
            byte[] bytes = null;
            Image image = imageReader.acquireLatestImage();
            try {

                ByteBuffer buffer = image.getPlanes()[0].getBuffer();
                bytes = new byte[buffer.capacity()];
                buffer.get(bytes);
                //use the bytes to manipulate
            } catch (Exception e) {
                e.printStackTrace();
            }
            image.close();
            imageReader.close();

        }

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

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