Android Camera2开启自动曝光功能
程序员文章站
2023-12-28 20:31:58
本文实例为大家分享了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); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
推荐阅读
-
Android 取消蓝牙配对框实现自动配对功能
-
Android编程实现canvas绘制柱状统计图功能【自动计算宽高及分度值、可左右滑动】
-
Android编程实现canvas绘制饼状统计图功能示例【自动适应条目数量与大小】
-
Android实现短信验证码自动填写功能
-
Android开发之多线程中实现利用自定义控件绘制小球并完成小球自动下落功能实例
-
Android编程实现TextView垂直自动滚动功能【附demo源码下载】
-
Android开发之文本内容自动朗读功能实现方法
-
Android 取消蓝牙配对框实现自动配对功能
-
Android实现短信验证码自动填写功能
-
Android开发之多线程中实现利用自定义控件绘制小球并完成小球自动下落功能实例