1

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();
                        }
                    }
                }
            };

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

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138

1 Answers1

5

aquireNextImage - Will fetch the next image from ImageReader Queue

aquireLatestImage - Will even fetch the next image from ImageReader Queue by deleting older Images in Queue .

For Reference : Image Reader API

Rajan Kali
  • 12,627
  • 3
  • 25
  • 37