【问题标题】:CameraX preview not showing anything when front camera is selected选择前置摄像头时,CameraX 预览不显示任何内容
【发布时间】:2019-11-22 10:27:46
【问题描述】:

我正在尝试使用 CameraX 库来使用前置摄像头捕捉图像。但是当相机启动时,预览只显示黑屏。这是配置:

val previewConfig = PreviewConfig.Builder().apply {
            setTargetResolution(Size(640, 480))
            setLensFacing(CameraX.LensFacing.FRONT)
        }.build()

        preview = Preview(previewConfig)

        preview.setOnPreviewOutputUpdateListener {
            val parent = viewFinder.parent as ViewGroup
            parent.removeView(viewFinder)
            parent.addView(viewFinder, 0)

            viewFinder.surfaceTexture = it.surfaceTexture
            updateTransform()
        }

        val imageCaptureConfig = ImageCaptureConfig.Builder()
            .apply {
                setCaptureMode(ImageCapture.CaptureMode.MIN_LATENCY)
            }.build()

        imageCapture = ImageCapture(imageCaptureConfig)

        val analyzerConfig = ImageAnalysisConfig.Builder().apply {
            setImageReaderMode(
                ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
        }.build()

        analyzerUseCase = ImageAnalysis(analyzerConfig).apply {
            setAnalyzer(executor, LuminosityAnalyzer())
        }
        CameraX.bindToLifecycle(this, preview, imageCapture)

但它与setLensFacing(CameraX.LensFacing.BACK) 配合得很好。此外,如果我从 bindToLifeCyle 方法中删除 ImageCapture 对象,我可以看到前置摄像头的预览。

CameraX.bindToLifecycle(this, preview, /*imageCapture*/)

请指教。

【问题讨论】:

  • 你解决了吗?
  • 我也遇到了同样的问题,请问您有解决办法吗?

标签: android kotlin camera android-architecture-components android-jetpack


【解决方案1】:

您还需要为 imageCaptureConfig 将 setLensFacing 设置为 front。 我也面临同样的问题,但你的问题解决了我的问题:p

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多