简体   繁体   English

使用Camera2 Api的LED手电筒有问题吗?

[英]Problems with LED Flashlight by using Camera2 Api?

I am trying to turn the flashlight on as the camera starts but here is what is actually happening. 我试图在照相机启动时打开手电筒,但这实际上是在发生什么。 My flashlight turns on and then its goes off after a couple of milliseconds. 我的手电筒打开,然后在几毫秒后熄灭。 I am really confused as what is causing that to happen. 我真的很困惑,是什么导致了这种情况的发生。 I am using the camera2 api and I am targeting devices with api >21 This is what I tried so far. 我正在使用camera2 API,并且将api> 21定位为设备。这是我到目前为止尝试过的方法。

@InsaneCat is right ( see this link ) @InsaneCat是正确的( 请参阅此链接

Remove your calls to turnOnFlashLight and do: 删除对turnOnFlashLight的调用,然后执行以下操作:

In protected void createCameraPreview() protected void createCameraPreview()

...
Surface surface = new Surface(texture);
captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);

// Add this line:
captureRequestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);

captureRequestBuilder.addTarget(surface);
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM