当前位置: 萬仟网 > 移动技术>移动开发>Android > Android Camera2开启自动曝光功能

Android Camera2开启自动曝光功能

2022年01月04日 Android 我要评论
本文实例为大家分享了android camera2开启自动曝光功能的具体代码,供大家参考,具体内容如下首先,打开3a的总开关:capturerequest.builder builder.set(ca

本文实例为大家分享了android camera2开启自动曝光功能的具体代码,供大家参考,具体内容如下

首先,打开3a的总开关:

capturerequest.builder builder.set(capturerequest.control_mode, camerametadata.control_mode_auto);

获取支持的 ae fps range:

list<int[]> ae_fps_ranges = new arraylist<>();
for (range<integer> r : characteristics.get(cameracharacteristics.control_ae_available_target_fps_ranges)) {
    ae_fps_ranges.add(new int[] {r.getlower(), r.getupper()});
}
collections.sort(ae_fps_ranges, new cameracontroller.rangesorter());

然后,设置fps:

builder.set(capturerequest.control_ae_target_fps_range, ae_target_fps_range);

最后,根据 flash_mode 设置 ae_mode

switch(flash_value) {
   case "flash_off":
       builder.set(capturerequest.control_ae_mode, camerametadata.control_ae_mode_on);
       builder.set(capturerequest.flash_mode, camerametadata.flash_mode_off);
       break;
   case "flash_auto":
       // note we set this even in fake flash mode (where we manually turn torch on and off to simulate flash) so we
       // can read the flash_required state to determine if flash is required
   /*if( use_fake_precapture || cameracontroller2.this.want_expo_bracketing )
       builder.set(capturerequest.control_ae_mode, camerametadata.control_ae_mode_on);
   else*/
       builder.set(capturerequest.control_ae_mode, camerametadata.control_ae_mode_on_auto_flash);
       //这里flash_mode可以设置为任意值,因为ae_mode优先级高
       builder.set(capturerequest.flash_mode, camerametadata.flash_mode_off);
       break;
   case "flash_on":
       // see note above for "flash_auto" for why we set this even fake flash mode - arguably we don't need to know
       // about flash_required in flash_on mode, but we set it for consistency...
   /*if( use_fake_precapture || cameracontroller2.this.want_expo_bracketing )
       builder.set(capturerequest.control_ae_mode, camerametadata.control_ae_mode_on);
   else*/
       builder.set(capturerequest.control_ae_mode, camerametadata.control_ae_mode_on_always_flash);
       builder.set(capturerequest.flash_mode, camerametadata.flash_mode_off);
       break;
   case "flash_torch":
       builder.set(capturerequest.control_ae_mode, camerametadata.control_ae_mode_on);
       builder.set(capturerequest.flash_mode, camerametadata.flash_mode_torch);
       break;
   case "flash_red_eye":
       // not supported for expo bracketing or burst
       if( cameracontroller2.this.burst_type != bursttype.bursttype_none )
           builder.set(capturerequest.control_ae_mode, camerametadata.control_ae_mode_on);
       else
           builder.set(capturerequest.control_ae_mode, camerametadata.control_ae_mode_on_auto_flash_redeye);
       builder.set(capturerequest.flash_mode, camerametadata.flash_mode_off);
       break;
   case "flash_frontscreen_auto":
   case "flash_frontscreen_on":
   case "flash_frontscreen_torch":
       builder.set(capturerequest.control_ae_mode, camerametadata.control_ae_mode_on);
       builder.set(capturerequest.flash_mode, camerametadata.flash_mode_off);
       break;
}

查看每帧的曝光参数:

cameracapturesession.capturecallback{
    @override
    public void oncapturecompleted(@nonnull cameracapturesession session, @nonnull capturerequest request, @nonnull totalcaptureresult result) {
        long capture_result_exposure_time = result.get(captureresult.sensor_exposure_time);
        long capture_result_sensitivity = result.get(captureresult.sensor_sensitivity);
    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持萬仟网。

(0)
打赏 微信扫一扫 微信扫一扫

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2022  萬仟网 保留所有权利. 粤ICP备17035492号-1
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com