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 ?
`
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With