使用Android camera2手动对焦闪光灯

如何使用
Android camera2 api使用闪光灯进行手动(触控)对焦?

我的captureRequest设置是:
 1. type – TEMPLATE_PREVIEW
 2. CONTROL_AE_MODE – CONTROL_AE_MODE_OFF
 3. FLASH_MODE – FLASH_MODE_SINGLE
 4. CONTROL_AF_TRIGGER – CONTROL_AF_TRIGGER_START

用法:

CaptureSession.capture(captureRequest.build(), captureCallback, null);

结果:
如果有足够的光线,相机会聚焦.否则闪光灯会快速闪烁并且对焦失败.

最佳答案 您可以通过以下方式尝试使用闪光灯执行手动(触摸)对焦:

mPreviewBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH);

使用TRIGGER时,同时使用AE和AF:

mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
mPreviewBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);

然后:

mCameraCaptureSession.setRepeatingRequest(mPreviewBuilder.build(), mPreviewSessionCallback, mHandler);
点赞