简体   繁体   English

如何为在cameraX中完成的焦点添加监听器

[英]How to add a Listener for focus done in cameraX

I am trying to implement manual focus on CameraX.我正在尝试对 CameraX 实施手动对焦。 but i don't know how to check that where startFocusAndMetering completed or not.但我不知道如何检查 startFocusAndMetering 在哪里完成。

I tried something like this我试过这样的事情

 val focusListenableFuture = camera?.cameraControl?.startFocusAndMetering(action)

I found that there is a method isDone() which can check weather focusing completed or not我发现有一个方法isDone()可以检查天气聚焦是否完成

how can i use it with focusListenableFuture?.addListener() to listen weather focusing completed or not我如何将它与focusListenableFuture 一起使用? .addListener()来收听天气聚焦是否完成

You can use FocusMeteringResult#isFocusSuccessful() :您可以使用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.如果在 FocusMeteringAction 中请求 AF 但当前相机不支持 AF,则返回 true。 If AF is not requested, it will return false.如果没有请求 AF,它将返回 false。

val focusListenableFuture  = camera?.cameraControl?.startFocusAndMetering(action)
focusListenableFuture.addListener( {
    val result = focusListenableFuture.get()
    val isSuccessful = result.isFocusSuccessful
}, ContextCompat.getMainExecutor(context))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM