Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageReader maxImages (2) has already been acquired in background task

Tags:

java

android

I am using ImageReader with Handler in order to get image in background. But i am getting:

Fatal Exception: java.lang.IllegalStateException maxImages (2) has already been acquired, call #close before acquiring more.

 private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
        = new ImageReader.OnImageAvailableListener() {

    @Override
    public void onImageAvailable(ImageReader reader) {
        mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), CameraFragment.this));
    }

};

On my background task is :

    private static class ImageSaver implements Runnable {

    /**
     * The JPEG image
     */
    private final Image mImage;

    BaseCameraFragment cameraFragmentContext;

    public ImageSaver(Image image, BaseCameraFragment cameraFragmentContext) {
        mImage = image;
        this.cameraFragmentContext = cameraFragmentContext;
    }

    @Override
    public void run() {
        ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
        cameraFragmentContext.photoReady(new ByteBufferInputStream(buffer));
        mImage.close();
    }

}

How can i solve this issue ?

like image 489
Nizomjon Hajiyev Avatar asked Aug 12 '17 12:08

Nizomjon Hajiyev


1 Answers

`

private ImageReader.OnImageAvailableListener imageAvailableListener = new ImageReader.OnImageAvailableListener()
{
    @Override
    public void onImageAvailable(ImageReader reader) {
        Image img = mReader.acquireLatestImage();

        //mReader.close();
       img.close();
    }
};

`

just use img.close(); can solution it

like image 64
gong situ Avatar answered Oct 30 '22 03:10

gong situ