IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> Android Camera AE和AF的设置 -> 正文阅读

[移动开发]Android Camera AE和AF的设置

在这里插入图片描述
以geekcamera为例,当关闭闪光灯时,flash mode = 0,代表flash为off模式;
ae mode = 1,代表ae为off模式,flash state = 2,代表flash处于 ready状态,表示没有打闪。
在这里插入图片描述
当闪光灯设置为auto时,是通过设置ae mode 控制的。flash mode = 0,代表flash为off模式;
ae mode = 2,代表ae为on模式,flash state = 2,代表flash处于 ready状态,表示没有打闪;flash state = 3,代表flash处于 fired状态,表示打闪了。在这里插入图片描述
在这里插入图片描述

具体代码逻辑

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

只要flash mode不是auto,并且需要打闪的时候,就需要做预闪(precapture)

boolean needs_flash = capture_result_ae != null && capture_result_ae != CaptureResult.CONTROL_AE_STATE_CONVERGED;
if( camera_settings.flash_value.equals("flash_auto") && !needs_flash ) {
	// if we call precapture anyway, flash wouldn't fire - but we tend to have a pause
	// so skipping the precapture if flash isn't going to fire makes this faster
	if( MyDebug.LOG )
		Log.i(TAG, "flash auto, but we don't need flash");
	call_takePictureAfterPrecapture = true;
}
else {
	call_runPrecapture = true;
}

if( call_runPrecapture ) {
	runPrecapture();
}

runPrecapture逻辑

runPrecapture() {
	final CaptureRequest.Builder precaptureBuilder = mCameraDevice.createCaptureRequest(previewIsVideoMode ? CameraDevice.TEMPLATE_VIDEO_SNAPSHOT : CameraDevice.TEMPLATE_STILL_CAPTURE);
	precaptureBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE);

	camera_settings.setupBuilder(precaptureBuilder, false);
	precaptureBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_IDLE);
	precaptureBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_IDLE);

	precaptureBuilder.addTarget(getPreviewSurface());

	state = STATE_WAITING_PRECAPTURE_START;
	precapture_state_change_time_ms = System.currentTimeMillis();

	// first set precapture to idle - this is needed, otherwise we hang in state STATE_WAITING_PRECAPTURE_START, because precapture already occurred whilst autofocusing, and it doesn't occur again unless we first set the precapture trigger to idle
	if( MyDebug.LOG )
	Log.i(TAG, "capture with precaptureBuilder");
	captureSession.capture(precaptureBuilder.build(), previewCaptureCallback, handler);
	captureSession.setRepeatingRequest(precaptureBuilder.build(), previewCaptureCallback, handler);

	// now set precapture
	precaptureBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);
	captureSession.capture(precaptureBuilder.build(), previewCaptureCallback, handler);
}

这里将state 设置为了STATE_WAITING_PRECAPTURE_START,当captureSession.capture()调用完后,会执行到CameraCaptureSession的回调函数onCaptureCompleted(),在此回调函数中我们需要判断AE的状态是否等于CaptureResult.CONTROL_AE_STATE_PRECAPTURE,如果等于,那么执行takePictureAfterPrecapture()
takePictureAfterPrecapture()的逻辑

takePictureAfterPrecapture(){
	stillBuilder = mCameraDevice.createCaptureRequest(previewIsVideoMode ? CameraDevice.TEMPLATE_VIDEO_SNAPSHOT : CameraDevice.TEMPLATE_STILL_CAPTURE);
	stillBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE);
	stillBuilder.setTag(new RequestTagObject(RequestTagType.CAPTURE));
	camera_settings.setupBuilder(stillBuilder, true);
	stillBuilder.addTarget(imageReader.getSurface());
	captureSession.capture(stillBuilder.build(), previewCaptureCallback, handler);
	playSound(MediaActionSound.SHUTTER_CLICK);
}
  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2021-11-19 17:44:27  更:2021-11-19 17:46:39 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 3:32:38-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码