栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Android Camera2 开启自动曝光

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android Camera2 开启自动曝光

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

CaptureRequest.Builder builder.set(CaptureRequest.CONTROL_MODE, Camerametadata.CONTROL_MODE_AUTO);

获取支持的 AE FPS Range:

List ae_fps_ranges = new ArrayList<>();
for (Range 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
   
       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...
   
       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);
	}
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/694081.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号