You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android CameraX:如何获取ImageAnalysis关联的自动对焦状态

获取CameraX ImageAnalysis中图像的自动对焦状态

要获取ImageAnalysis回调中对应图像的AF状态,核心是拿到该图像捕获时对应的Camera2 TotalCaptureResult,CameraX在1.1.0及以上版本提供了直接获取的方式,具体步骤如下:

  • 在analyze(@NonNull ImageProxy image)方法中,先通过image.getImageInfo()获取图像信息实例:
    ImageInfo imageInfo = image.getImageInfo();
    
  • 调用imageInfo.getCameraCaptureResult()获取对应的TotalCaptureResult(注意该方法可能返回null,需做判空处理):
    TotalCaptureResult captureResult = (TotalCaptureResult) imageInfo.getCameraCaptureResult();
    if (captureResult != null) {
        // 获取自动对焦状态
        Integer afState = captureResult.get(TotalCaptureResult.CONTROL_AF_STATE);
        // 后续可根据afState判断对焦状态,比如AF_STATE_FOCUSED_LOCKED表示已对焦锁定
    }
    

注意事项

  • 确保使用CameraX 1.1.0及以上版本,getCameraCaptureResult()方法是在这个版本新增的;
  • 部分设备可能因硬件限制无法返回有效TotalCaptureResult,需做好空值兼容;
  • 若无法升级CameraX版本,可通过监听CameraControl的AF状态,但这种方式无法保证状态与当前图像严格对应,仅能作为近似参考。

内容的提问来源于stack exchange,提问作者ant1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 13:01:19