CameraX库如何打开/关闭手电筒? [英] How does CameraX library can turn ON/OFF the torch?
问题描述
我正在开发一种功能,可以将手电筒切换为开/关状态.几天前,我们在 io2019 中看到了来自Google的新库.我想出了一个主意,为什么不使用它.
一段时间后,我看不到任何可能性,使用图书馆里唯一的火炬.
即使在官方文档中,我也找不到适合我的任何信息,而且,他们中的示例应用程序也不必处理我的案件.
您是否想到了什么是易于实现的,或者您知道如何使用CameraX做到这一点?
我担心使用camera或camera2,因为要粘贴的代码量太糟糕了.
链接:
[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
您可以通过以下方法检查火炬是否可用:
val camera = cameraProvider.bindToLifecycle(lifecycleOwner,cameraSelector,预览,imageAnalyzer)camera.cameraInfo.hasFlashUnit()
您可以通过以下方式启用割炬:
camera.cameraControl.enableTorch(true)
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.
Do you have something in mind what is easy to implement or perhaps you know how to do it with CameraX?
I am worried about using camera or camera2 because the amount of code to be paste is terrible.
Links:
[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 is an Android Jetpack library that was built with the intent to make camera development easier.
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库如何打开/关闭手电筒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!