来自api 21及更高版本的onAutoFocused()没有回调

时间:2016-10-05 13:16:31

标签: android camera2

如何使用camera2 api在android中自动捕获照片? api 21及以上版本没有像onAutoFocused()那样的回调。

1 个答案:

答案 0 :(得分:1)

您必须手动触发AF和AE。 标准管道是:

  1. CONTROL_AF_TRIGGER设置为CONTROL_AF_TRIGGER_START中用于预览的CaptureRequest.Builder,并通过CameraCaptureSession capture方法提交给会话。调用捕获后,请记住在CaptureRequest.Builder中将CONTROL_AF_TRIGGER重置为CONTROL_AF_TRIGGER_IDLE进行预览;
  2. 等待AF完成检查预览回调中的CaptureResult.CONTROL_AF_STATE of TotalCaptureResult是否为CONTROL_AF_STATE_FOCUSED_LOCKED || CONTROL_AF_STATE_NOT_FOCUSED_LOCKED || CONTROL_AF_STATE_PASSIVE_FOCUSED || CONTROL_AF_STATE_PASSIVE_UNFOCUSED
  3. 完成AF后,在您用于预览的CONTROL_AE_PRECAPTURE_TRIGGER中触发AE设置CONTROL_AE_PRECAPTURE_TRIGGER_STARTCaptureRequest.Builder,并通过CameraCaptureSession capture方法提交至会话。调用捕获后,请记住在CaptureRequest.Builder中将CONTROL_AE_PRECAPTURE_TRIGGER重置为CONTROL_AE_PRECAPTURE_TRIGGER_IDLE进行预览;
  4. 等待AE完成检查预览回调中的CaptureResult.CONTROL_AE_STATE of TotalCaptureResult是否为CONTROL_AE_STATE_CONVERGED || CONTROL_AE_STATE_FLASH_REQUIRED || CONTROL_AE_STATE_LOCKED
  5. 现在你可以拍照,专注且曝光良好
  6. 我也有经验可以同时触发AF e AE(步骤1-3)并同时等待它们(步骤2-4)。