2

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.

Dem0n13
  • 766
  • 1
  • 13
  • 37
  • The emulator is not relevant for such experiments. As for Pixel, what resolution does it pick up when you request 4:3 aspect ratio? The cameraX library may be unprepared to handle square images. – Alex Cohn Sep 16 '19 at 16:56
  • when I set 3:4 it chooses the max resolution. But the documentation says that 1:1 ratio - is one of the valid usage cases. My question shows that library can crop original image to square (352x288px to 288x288px) so it seems that it is bug. – Dem0n13 Sep 18 '19 at 08:10
  • See https://issuetracker.google.com/issues/138814839 – Alex Cohn Sep 18 '19 at 17:50
  • See also https://stackoverflow.com/a/57288661/192373 – Alex Cohn Oct 04 '19 at 03:50

0 Answers0