1

我正在使用 Camera2 API 连续拍照并且工作正常,在这里我可以使用以下代码保存捕获的图像:

ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
                @Override
                public void onImageAvailable(ImageReader reader) {
                    Image image = null;
                    try {

//                        image = reader.acquireLatestImage();
                        image = reader.acquireNextImage();
                        ByteBuffer buffer = image.getPlanes()[0].getBuffer();
                        byte[] bytes = new byte[buffer.capacity()];
                        buffer.get(bytes);
                        save(bytes);
                    } catch (FileNotFoundException e) {
                        logFile.writeCrashLog(TAG + ": " + e.toString());
                        hideProgressDialog();
                    } catch (IOException e) {
                        logFile.writeCrashLog(TAG + ": " + e.toString());
                        hideProgressDialog();
                    } catch (Exception e) {
                        logFile.writeCrashLog(TAG + ": " + e.toString());
                        hideProgressDialog();
                    } finally {
                        if (image != null) {
                            image.close();
                        }
                    }
                }

                private void save(byte[] bytes) throws IOException {
                    OutputStream output = null;
                    try {
                        output = new FileOutputStream(AndroidCameraApiActivity.this.file);
                        output.write(bytes);
                    } catch (Exception e) {
                        logFile.writeCrashLog(TAG + ": " + e.toString());
                        hideProgressDialog();
                    } finally {
                        if (null != output) {
                            output.close();
                        }
                    }
                }
            };

在这里我想知道通过acquireLatestImageacquireNextImage获取图像的最佳情况是什么?适合获得连续图像。

4

1 回答 1

5

aquireNextImage - 将获取下一张图片ImageReader Queue

aquireLatestImage - 甚至会ImageReader通过删除Queue.

供参考:图像阅读器 API

于 2017-10-27T07:52:46.793 回答