我正在尝试使用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*/)
请给我建议。
发布于 2020-04-26 22:28:04
对于imageCaptureConfig,您还需要将setLensFacing设置为前端。我也面临着同样的问题,但你的问题解决了我的问题:
https://stackoverflow.com/questions/58992267
复制相似问题