Stack Exchange
While capturing image camera gets freeze in Redmi Note7 s camera2 API Android
In below code i have just read image and save it into gallary.
            public void onImageAvailable(ImageReader reader) {
                Image image = null;
                try {
                    image = reader.acquireLatestImage();
                    buffer = image.getPlanes()[0].getBuffer();
                    bytes = new byte[buffer.capacity()];
                    buffer.get(bytes);
                    save(bytes);

                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                } finally {
                    if (image != null) {
                        image.close();
                    }
                }

private void save(byte[] bytes) throws IOException {
                if (!myDir.exists()) {
                    myDir.mkdirs();
                }

                Random generator = new Random();
                int n = 10000;
                n = generator.nextInt(n);
                String fname = "Image-" + n + ".png";

                File file = new File(myDir, fname);

                if (file.exists()) file.delete();



                OutputStream output = null;
                try {
                    output = new FileOutputStream(file);
                    output.write(bytes);
                    scanFile(file.getAbsolutePath());

//                        final int rotation = getImageOrientation(file.getAbsolutePath());
                } finally {
                    if (null != output) {
                        output.close();
                    }
                }
            }


My guess is, that you close your Image before every operation has finished. First get your Image like:
private ImageReader mImageReader;
private final ImageReader.OnImageAvailableListener mOnImageAvailableListener = new
        ImageReader.OnImageAvailableListener() {
            @Override
            public void onImageAvailable(ImageReader reader) {

                if(count==0) {
                    mBackgroundHandler.post(new ImageSaver(reader.acquireLatestImage()));
                    ++count;
                }
            }
        };

After that you can do what you want to do in a separate thread like:
private class ImageSaver implements Runnable {

    private final Image mImage;

    public ImageSaver(Image image) {
        mImage = image;
    }

    @Override
    public void run() {


        //Do what you want to do here and close your Image after that. Code here!!

        mImage.close();
        --count;
    }
}

I use int ++count --count to control my flow. 
