Fix app crash when no image is read in camera block.

This commit is contained in:
Sergio Martínez Portela 2020-06-05 19:19:38 +02:00
parent d07d73b56a
commit 13fa966557

View File

@ -69,6 +69,8 @@ public class CameraStreamer implements Part {
private ImageReader imageReader = null;
private HandlerThread _thread = null;
private Handler _handler = null;
private static final int CAPTURE_IMAGE_WIDTH = 256;
private static final int CAPTURE_IMAGE_HEIGHT = 256;
private CameraStreamer(String id, PartGrid partGrid, int left, int top, int right, int bottom) {
_id = id;
@ -335,10 +337,14 @@ public class CameraStreamer implements Part {
}
}
this.imageReader = ImageReader.newInstance(100, 100, ImageFormat.JPEG, 30);
this.imageReader = ImageReader.newInstance(CAPTURE_IMAGE_WIDTH, CAPTURE_IMAGE_HEIGHT, ImageFormat.JPEG, 30);
this.imageReader.setOnImageAvailableListener((ImageReader.OnImageAvailableListener) newImageReader -> {
Image latestImage = newImageReader.acquireLatestImage();
if (latestImage == null) {
return;
}
CameraStreamer.this.onNewImage(latestImage);
latestImage.close();
}, new Handler());