Flashlight Camera2 API [英] Flashlight Camera2 API

查看:153
本文介绍了Flashlight Camera2 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在Android Camera2 API中同时使用相机预览和手电筒吗?

Can I use camera preview and flashlight at the same time in Android Camera2 API?

当我尝试使用CameraManager.setTorchMode(String cameraId, boolean enabled)时,在未打开相机的情况下可以正常工作.但是当Camera打开并且尝试setTorchMode时,会收到此异常:

When I try use CameraManager.setTorchMode(String cameraId, boolean enabled) it's work fine when camera is not opened. But when Camera is open and I try setTorchMode I receive this exception:

CameraService:setTorchMode:摄像机0的割炬模式不可用,因为正在使用摄像机

CameraService: setTorchMode: torch mode of camera 0 is not available because camera is in use

推荐答案

该错误表明该摄像头已经在使用中.

The error is indicating that the camera in question, is already in use.

您需要相应地设置FLASH_MODECONTROL_AE_MODE.

mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
// Then Send request to current camera session
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), null, null);

这篇关于Flashlight Camera2 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆