问题描述
我想使用camera2 api在android中同时打开相机并设置手电筒模式.但是由于打开相机的优先级更高,手电筒模式被关闭.如何同时使用两者?
I want to open camera and set torch mode at the same time in android using camera2 api. But because of higher priority of open camera, torch mode is switched off. How can I use both at the same time?
private void openCamera() 抛出 CameraAccessException {CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);cameraId = cameraManager.getCameraIdList()[0];
private void openCamera() throws CameraAccessException { CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); cameraId = cameraManager.getCameraIdList()[0];
CameraCharacteristics cc = cameraManager.getCameraCharacteristics(cameraId);
StreamConfigurationMap map = cc.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
imageDimensions = map.getOutputSizes(SurfaceTexture.class)[0];
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
return;
}
cameraManager.openCamera(cameraId, stateCallback, null);
cameraManager.setTorchMode(cameraId, true);
}
在camera2 api中不能同时使用两者
using both at same time is not possible in camera2 api
推荐答案
一旦相机打开,您就可以使用 FLASH_MODE 并将其设置为 TORCH 在您的预览捕获请求中.
Once the camera is open, you can use FLASH_MODE and set it to TORCH in your preview capture request.
这意味着您需要将 AE_MODE 保持为ON 或 OFF,不是其中一种 FLASH 模式,因此自动曝光不会控制闪光灯.
This means you need to keep AE_MODE to either ON or OFF, not one of the FLASH modes, so that auto-exposure isn't controlling the flash.
这篇关于同时打开相机并设置手电筒模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!