gpt4 book ai didi

android-camerax - 不能使用camerax拍摄多张图片

转载 作者:行者123 更新时间:2023-12-04 02:44:35 33 4
gpt4 key购买 nike

我正在尝试使用 camerax 拍摄多张照片,但只拍摄了第一张照片,代码和日志输出将显示我的意思。

这是代码:

        Log.d(TAG, "------------------ taking new picture1");
mImageCapture.takePicture(new ImageCapture.OnImageCapturedListener() {
@Override
public void onCaptureSuccess(ImageProxy imageProxy, int rotationDegrees) {
Image image = imageProxy.getImage();
Log.d(TAG, "taking new picture onCapture Success 1 called");
}

@Override
public void onError(ImageCapture.UseCaseError useCaseError, String message, @Nullable Throwable cause) {
super.onError(useCaseError, message, cause);
Log.d(TAG, "--------- error in image capture 1" + message);


}
});

Log.d(TAG, "------------------ taking new picture 2");
mImageCapture.takePicture(new ImageCapture.OnImageCapturedListener() {
@Override
public void onCaptureSuccess(ImageProxy imageProxy, int rotationDegrees) {
Image image = imageProxy.getImage();
Log.d(TAG, "taking new picture onCapture Success 2 called");


}

@Override
public void onError(ImageCapture.UseCaseError useCaseError, String message, @Nullable Throwable cause) {
super.onError(useCaseError, message, cause);
Log.d(TAG, "--------- error in image capture 2" + message);
}
});

相关的日志输出是:
2019-09-04 12:23:00.978 28970-29006/com.example.david.digified_android D/ScanDocumentFragment: ------------------ taking new picture1
2019-09-04 12:23:00.980 28970-29006/com.example.david.digified_android D/ScanDocumentFragment: ------------------ taking new picture 2
2019-09-04 12:23:02.063 28970-28970/com.example.david.digified_android D/ScanDocumentFragment: taking new picture onCapture Success 1 called

但是 在名为 的 onCapture Success 2 上拍摄新照片从未发生过

虽然根据文档拍摄两张照片并没有错:

TakePicture returns immediately and a listener is called to provide the results after the capture completes. Multiple calls to takePicture will take pictures sequentially starting after the previous picture is captured.



https://developer.android.com/reference/androidx/camera/core/ImageCapture?hl=en

最佳答案

这似乎是图书馆的问题,这是错误:
https://issuetracker.google.com/issues/140518887
更新
根据团队对该问题的评论,这似乎不是错误,问题是我在完成处理后必须调用 image.close(); 以便我的代码应该是:

Log.d(TAG, "------------------ taking new picture1");
mImageCapture.takePicture(new ImageCapture.OnImageCapturedListener() {
@Override
public void onCaptureSuccess(ImageProxy imageProxy, int rotationDegrees) {
Image image = imageProxy.getImage();
Log.d(TAG, "taking new picture onCapture Success 1 called");
image.close();
}

});

Log.d(TAG, "------------------ taking new picture 2");
mImageCapture.takePicture(new ImageCapture.OnImageCapturedListener() {
@Override
public void onCaptureSuccess(ImageProxy imageProxy, int rotationDegrees) {
Image image = imageProxy.getImage();
Log.d(TAG, "taking new picture onCapture Success 2 called");
image.close();
}
});

关于android-camerax - 不能使用camerax拍摄多张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57786636/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com