1

I want to get the best quality for square aspect ratio and setup the next preview and capture configs for CameraX.

val SQUARE_ASPECT_RATIO = Rational(1, 1)

val previewConfig = PreviewConfig.Builder().apply {
    setTargetAspectRatio(SQUARE_ASPECT_RATIO)
    setTargetRotation(viewFinder.display.rotation)
}.build()
preview = Preview(previewConfig)

val imageCaptureConfig = ImageCaptureConfig.Builder().apply {
    setCaptureMode(ImageCapture.CaptureMode.MAX_QUALITY)
    setTargetAspectRatio(SQUARE_ASPECT_RATIO)
    setTargetRotation(viewFinder.display.rotation)
}.build()
imageCapture = ImageCapture(imageCaptureConfig)

CameraX.bindToLifecycle(this, preview, imageCapture)

CameraX chooses 352x288px resolution, so result image resolution equals 288x288px. From documentation it should be the highest resolution available for current device, but it is not.

Tested on emulator and Google Pixel 3.

4

0 回答 0