欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

Android Camera2开启自动曝光功能

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);
    }
}

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

上一篇:

下一篇: