3

我不断收到此错误。当我尝试使用 CameraX 库打开相机时。相同的代码在少于 pie 的其他设备上运行。但不在饼图上运行(相机未显示)

这是我的代码:而且我还在我的项目中使用生活数据会导致任何问题吗?

  val previewConfig = PreviewConfig.Builder()
            .setLensFacing(CameraX.LensFacing.BACK)
            .build()
    val preview = Preview(previewConfig)
    preview.setOnPreviewOutputUpdateListener { previewOutput ->
        _textureView.surfaceTexture = previewOutput.surfaceTexture
    }
    val imageAnalysisConfig = ImageAnalysisConfig.Builder()
        .build()
    val imageAnalysis = ImageAnalysis(imageAnalysisConfig)
    val qrCodeAnalyzer = QRCodeAnalyzer { qrCodes ->
        qrCodes.forEach {
            Log.d("MainActivity", "QR Code detected: `${it.rawValue}.")`
            val intent = intent.putExtra("RESULT",it.rawValue)
            setResult(Activity.RESULT_OK,intent)
            finish()
        }
    }

    imageAnalysis.analyzer = qrCodeAnalyzer

    // We need to bind preview and imageAnalysis use cases
    CameraX.bindToLifecycle(this as LifecycleOwner , preview, imageAnalysis)

日志:查看我收到的日志

 E/GLConsumer: [SurfaceTexture-0-3196-1] updateAndRelease: GLConsumer is not attached to an OpenGL ES context
E/GLConsumer: [SurfaceTexture-0-3196-1] updateAndRelease: GLConsumer is not attached to an OpenGL ES context
E/GLConsumer: [SurfaceTexture-0-3196-1] updateAndRelease: GLConsumer is not attached to an OpenGL ES context
E/GLConsumer: [SurfaceTexture-0-3196-1] updateAndRelease: GLConsumer is not attached to an OpenGL ES context
4

1 回答 1

4

我只是有类似的问题。我按照https://stackoverflow.com/a/56121351/11977949的建议通过删除和重新添加 SurfaceTexture 来解决它。

您应该将 setOnPreviewOutputUpdateListener 更改为:

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

有关更多详细信息,请查看官方示例

于 2019-09-20T08:43:07.610 回答