如何为在 cameraX 中完成的焦点添加监听器
How to add a Listener for focus done in cameraX
我正在尝试在 CameraX 上实现手动对焦。但我不知道如何检查 startFocusAndMetering 是否完成。
我试过这样的东西
val focusListenableFuture = camera?.cameraControl?.startFocusAndMetering(action)
我发现有一个方法isDone()可以检查天气聚焦是否完成
我如何将它与 focusListenableFuture?.addListener() 一起使用来收听天气聚焦是否完成
您可以使用 FocusMeteringResult#isFocusSuccessful()
:
Returns if auto focus is successful.
If AF is requested in FocusMeteringAction but current camera does not
support AF, it will return true. If AF is not requested, it will
return false.
val focusListenableFuture = camera?.cameraControl?.startFocusAndMetering(action)
focusListenableFuture.addListener( {
val result = focusListenableFuture.get()
val isSuccessful = result.isFocusSuccessful
}, ContextCompat.getMainExecutor(context))
我正在尝试在 CameraX 上实现手动对焦。但我不知道如何检查 startFocusAndMetering 是否完成。
我试过这样的东西
val focusListenableFuture = camera?.cameraControl?.startFocusAndMetering(action)
我发现有一个方法isDone()可以检查天气聚焦是否完成
我如何将它与 focusListenableFuture?.addListener() 一起使用来收听天气聚焦是否完成
您可以使用 FocusMeteringResult#isFocusSuccessful()
:
Returns if auto focus is successful.
If AF is requested in FocusMeteringAction but current camera does not support AF, it will return true. If AF is not requested, it will return false.
val focusListenableFuture = camera?.cameraControl?.startFocusAndMetering(action)
focusListenableFuture.addListener( {
val result = focusListenableFuture.get()
val isSuccessful = result.isFocusSuccessful
}, ContextCompat.getMainExecutor(context))