简体   繁体   English

使用CameraX API拍照时,如何让flash一直亮着?

[英]How can I keep the flash continuously on while taking a picture using the CameraX API?

I am using the CameraX library to take pictures in my Android app, but I would like to keep the flash continuously on while the picture is being taken.我正在使用 CameraX 库在我的 Android 应用程序中拍照,但我想在拍照时让 flash 持续开启。 I've tried using the setFlashMode(FlashMode.ON) method of the ImageCapture class, but the flash only fires for a moment during the capture.我试过使用 ImageCapture class 的ImageCapture setFlashMode(FlashMode.ON)方法,但 flash 仅在捕获期间触发片刻。 There does not seem to be a flash mode setting available like FlashMode.TORCH or FLASH_TYPE_USE_TORCH_AS_FLASH that would allow for keeping the flash continuously on.似乎没有 flash 模式设置可用,如FlashMode.TORCHFLASH_TYPE_USE_TORCH_AS_FLASH允许保持 flash 持续开启。 Is there a way to achieve this using the CameraX API?有没有办法使用 CameraX API 来实现这一点?

I figured I'd add a button to turn on the torch and use that instead.我想我会添加一个按钮来打开手电筒并使用它来代替。 Just before taking the picture, I automatically turn it off and use the normal flash. This works because my goal is to enable users to illuminate a target in a dark place before taking the picture.就在拍照之前,我自动将其关闭并使用正常的 flash。之所以可行,是因为我的目标是让用户在拍照前能够在黑暗的地方照亮目标。

 camera = cameraProvider.bindToLifecycle(... ); if (camera.getCameraInfo().hasFlashUnit()) { camera.getCameraControl().enableTorch(true); }

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

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