问题
i have a textureview where i have implemented ontouch listener, i want when i touch the display to be able to focus, but there's a problem when setting setRepeatingRequest to build the display, it focuses only first time when i touch and after that i can touch 100x but still it has no effect, i want to enable flash on focusing and on capture but the flash stays on all the time as the camera does not focus, please help me, i'm stuck for 5 days at this task !
Here is my code : //meteringRectangleArr is the areas where i can focus (metering)
mPreviewCaptureRequestBuilder.set(
CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_CANCEL);
mPreviewCaptureRequestBuilder.set(
CaptureRequest.CONTROL_AF_REGIONS,
meteringRectangleArr);
mPreviewCaptureRequestBuilder.set(
CaptureRequest.CONTROL_AE_REGIONS,
meteringRectangleArr);
mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_MODE,
CaptureRequest.CONTROL_MODE_AUTO);
mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_AUTO);
mPreviewCaptureRequestBuilder.set(
CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_START);
if(flash_value == 1){
flash_startime = System.currentTimeMillis();
updateFlashingView();
mPreviewCaptureRequestBuilder.set(
CaptureRequest.FLASH_MODE,
CaptureRequest.FLASH_MODE_SINGLE);
}
else if (flash_value == 0){
mPreviewCaptureRequestBuilder.set(
CaptureRequest.FLASH_MODE,
CaptureRequest.FLASH_MODE_OFF);
}
try {
mCameraCaptureSession.setRepeatingRequest(
mPreviewCaptureRequestBuilder.build(),
null, mBackgroundHandler);
} catch (CameraAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
回答1:
remove this:
mPreviewCaptureRequestBuilder.set(
CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_START);
you should call CONTROL_AF_TRIGGER_START only once, using mCameraCaptureSession.capture.
I branched form google's Camera2Basic example and changed it to use CaptureRequest.CONTROL_AF_MODE_AUTO
instead of CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE
You can take the project from git and see how it works - https://github.com/pinhassi/android-Camera2Basic
来源:https://stackoverflow.com/questions/33355977/camera-preview-session-setrepeatingrequest-focus-issue-focuses-only-first-time