Reputation: 107
I am trying to use CameraX library to capture image using front camera. But when the camera is launched, preview is showing nothing but black screen. Here is the configurations:
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)
But it's working well with setLensFacing(CameraX.LensFacing.BACK)
. Also if i remove ImageCapture object from bindToLifeCyle method, i can see a preview with the front facing camera.
CameraX.bindToLifecycle(this, preview, /*imageCapture*/)
Please advise.
Upvotes: 2
Views: 1977
Reputation: 196
You also need to set setLensFacing to front for imageCaptureConfig. I was also facing the same issue , but your question solved my issue :p
Upvotes: 1