我尝试使用camera2 API从相机捕获图像数据。我主要使用的是从android Capture2RAW示例中获取的代码。在完全停止之前,只有少数图像通过(即调用onImageAvailable)。我尝试使用不同大小的RAW_SENSOR和JPEG格式捕获相同的结果。我做错了什么?
this.mImageReader = ImageReader.newInstance(width, height, ImageFormat.RAW_SENSOR, /*maxImages*/ 1);
Surface surface = this.mImageReader.getSurface();
final List<Surface> surfaces = Arrays.asList(surface);
this.mCamera.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {
// Callback methods here
}, null);
CaptureRequest.Builder captureRequestBuilder;
captureRequestBuilder = this.mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
captureRequestBuilder.addTarget(surface);
this.mCaptureRequest = captureRequestBuilder.build();
this.mCaptureSession.setRepeatingRequest(mCaptureRequest, null, null);
答案 0 :(得分:16)
修正了它。 ImageReader生成的图像需要关闭,否则会很快填满内存。
@Override
onImageAvailable(ImageReader reader) {
Image image = reader.acquireLatestImage();
// Process the image
image.close();
}