问题描述
我正在开发一项功能,可以将手电筒切换到开/关状态.几天前,我们在 io2019 中看到了来自 Google 的新库.我想出了一个主意,为什么不使用它.
I am developing a feature with the possibility of switching the torch into ON/OFF states. Some days ago, we saw a new library from Google in io2019. I came up with an idea, why not use it.
一段时间后,我看不到任何可能使用图书馆中唯一的手电筒.
After some time, I don't see any possibilities to use the only torch from the library.
即使在官方文档中,我也找不到任何适合我的信息,而且他们的示例应用程序也不必处理我的情况.
Even in the official documentation, I wasn't able to find any good pieces of information for me, what's more, the sample app from their also don't have to handle my case.
您有什么容易实现的想法,或者您知道如何使用 CameraX 来实现吗?
我担心使用相机或相机2,因为要粘贴的代码量很糟糕.
I am worried about using camera or camera2 because the amount of code to be paste is terrible.
链接:
[1] https://developer.android.com/training/camerax
[2] https://proandroiddev.com/android-camerax-preview-analyze-capture-1b3f403a9395
[3] https://github.com/android/camera/tree/master/CameraXBasic
[4] https://github.com/android/camera/tree/master/CameraXBasic
CameraX 是一个 Android Jetpack 库,旨在简化相机开发.
推荐答案
androidx.camera:camera-core:1.0.0-alpha10
你可以用这个检查手电筒是否可用:
You can check is torch available or not with this:
val camera = cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, preview, imageAnalyzer)
camera.cameraInfo.hasFlashUnit()
您可以通过以下方式启用手电筒:
And you can enable torch with:
camera.cameraControl.enableTorch(true)
这篇关于CameraX 库如何打开/关闭手电筒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!