Difference between acquireNextImage Vs acquireLatestImage

Shy*_*dda 1 android android-camera2 image-reader

I am working on Camera2 API to take pictures continuously and it's working fine, Here I am able to save the captured image using following code:

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();
                        }
                    }
                }
            };
Run Code Online (Sandbox Code Playgroud)

Here I want to know which is the best case to get the image by acquireLatestImage OR acquireNextImage? which suitable to get continuous images.

raj*_* ks 5

aquireNextImage - 将从中获取下一个图像ImageReader Queue

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

供参考:图像阅读器 API