小编Joh*_*ibe的帖子

Android-CameraX:在多个前置摄像头之间切换

我\xc2\xb4m 尝试编写我的第一个Android 相机应用程序,但它总是选择变焦相机而不是主相机。(我在华为P30 Pro上测试过)

\n\n

该代码基于官方的camerax示例应用程序(https://github.com/android/camera-samples/tree/master/CameraXBasic

\n\n

相关代码:

\n\n
/** Declare and bind preview, capture and analysis use cases */\nprivate fun bindCameraUseCases() {\n\n    // Get screen metrics used to setup camera for full screen resolution\n    val metrics = DisplayMetrics().also { viewFinder.display.getRealMetrics(it) }\n    Log.d(TAG, "Screen metrics: ${metrics.widthPixels} x ${metrics.heightPixels}")\n\n    val screenAspectRatio = aspectRatio(metrics.widthPixels, metrics.heightPixels)\n    Log.d(TAG, "Preview aspect ratio: $screenAspectRatio")\n\n    val rotation = viewFinder.display.rotation\n\n    // Bind the CameraProvider to the LifeCycleOwner\n\n    val cameraSelector = CameraSelector.Builder().requireLensFacing(lensFacing).build()\n\n    val cameraProviderFuture = ProcessCameraProvider.getInstance(requireContext())\n    cameraProviderFuture.addListener(Runnable …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-camerax

5
推荐指数
1
解决办法
8467
查看次数

标签 统计

android ×1

android-camerax ×1

kotlin ×1