我使用Camera2 API的触摸对焦实现出现问题。这是我的代码:
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
if (isMeteringAreaAESupported()) {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS,
new MeteringRectangle[]{focusArea});
}
if (isMeteringAreaAFSupported()) {
mPreviewRequestBuilder
.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[]{focusArea});
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_AUTO);
}
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_START);
try {
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), null,
mBackgroundHandler);
mManualFocusEngaged = true;
} catch (CameraAccessException e) {
// error handling
}
我看到的问题是,在短时间内多次调用上述代码时,某些设备上的闪光灯出现了怪异行为(即,在设置焦点之前,用户以太快的速度触摸屏幕)。例如,在S5上,似乎所有请求都已排队,如果用户触摸了几次,它们将一一执行一段时间。在我的Nexus 5上,闪光灯不会在请求之间闪烁,但会一直亮着,直到最后一个请求执行完毕。
我要做的就是像在Google相机中一样取消飞行中的请求。如果您使用Google相机开启闪光灯尝试相同的操作,则他们会在注册新触摸后立即取消请求。
我试过mCaptureSession.abortCaptures();
在上述方法之前添加,但是它的工作方式不同,因此也开始删除帧。mCaptureSession.stopRepeating();
完全没有任何区别。
显然,我必须执行捕获请求才能取消AF。
我已经在第一行之后添加了CANCEL触发器:
try {
mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
mBackgroundHandler);
// After this, the camera will go back to the normal state of preview.
mState = STATE_PREVIEW;
} catch (CameraAccessException e){
// log
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句