本文介绍了打开相机并同时设置手电筒模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用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 保持为开启或关闭,而不是闪光灯模式之一,因此自动曝光不会控制闪光灯.

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.

这篇关于打开相机并同时设置手电筒模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 06:14