gpt4 book ai didi

java - 相机 2 捕捉图像时预览已锁定

转载 作者:行者123 更新时间:2023-12-02 12:08:49 24 4
gpt4 key购买 nike

我已经使用camera2 Api实现了连拍图像捕获,它工作正常,拍摄速度为6 fps..bt我的问题是当它拍照时它会触发焦点锁定,这就是预览被锁定一小段时间的原因,我想删除它预览锁定,我希望始终启用预览,这是我的静态捕捉连拍,我正在遵循 googlescamera2 示例

private void captuteStillImage() {
try {
count = 0;
CaptureRequest.Builder captureBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

int rotation = getWindowManager().getDefaultDisplay().getRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
super.onCaptureCompleted(session, request, result);
//unlockFocus();
count++;
Log.e("count",count+"");
runOnUiThread(new Runnable() {
@Override
public void run() {
tv_count.setText(count+"");

}
});

if (count >= MAX_CAPTURE) {
unlockFocus();
}
Log.e("Image Capture", "Successfully");
}
};

// mCameraCaptureSession.capture(captureBuilder.build(), captureCallback, null);

List<CaptureRequest> captureList = new ArrayList<CaptureRequest>();
captureBuilder.addTarget(mImageReader.getSurface());
for (int i = 0; i < MAX_CAPTURE; i++) {
captureList.add(captureBuilder.build());
}
//mCameraCaptureSession.stopRepeating();
mCameraCaptureSession.captureBurst(captureList, captureCallback, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}

最佳答案

我在camera2basic( https://github.com/googlesamples/android-Camera2Basic )上对此进行了一些实验,发现如果我在获取图像后和保存图像之前调用解锁,我可以更快地恢复预览 - 我还删除了对 unLockFocus 的原始调用捕获回调。

    /**
* This a callback object for the {@link ImageReader}. "onImageAvailable" will be called when a
* still image is ready to be saved.
*/
private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
= new ImageReader.OnImageAvailableListener() {

@Override
public void onImageAvailable(ImageReader reader) {
Log.d(TAG,"onImageAvailable");

//Get the image
Image cameraImage = reader.acquireNextImage();

//Now unlock the focus so the UI does not look locked - note that this is a much earlier point than in the
//original Camera2Basic example from google as the original place was causing the preview to lock during any
//image manipulation and saving.
unlockFocus();

//Save the image file in the background - note check you have permissions granted by user or this will cause an exception.
mBackgroundHandler.post(new ImageSaver(getActivity().getApplicationContext(), cameraImage, outputPicFile);

}

};

但是,Camera2Basic 有很多回调,我发现当您开始测试 Activity 或 fragment 暂停和恢复的场景时,特别是如果您的应用程序也有其他异步回调,很容易陷入竞争条件可能会导致意外行为或崩溃。

如果您只是想要一个在拍照时更快返回预览的简单相机示例,那么基本的 FotoApparat 示例可能也值得一看:

关于java - 相机 2 捕捉图像时预览已锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46701959/

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