Search code examples
androidandroid-jetpackandroid-camerax

Setting target resolution for CameraX not working as in documentation


I want to capture photos with fixed resolution (i.e. 1200x1600) using CameraX library.

So according to documentation I can set target resolution for ImageCaptureConfig:

val imageCaptureConfig = ImageCaptureConfig.Builder()
    .setLensFacing(CameraX.LensFacing.BACK)
    .setCaptureMode(ImageCapture.CaptureMode.MAX_QUALITY)
    .setTargetResolution(Size(1200, 1600))
    .setTargetAspectRatio(Rational(3,4))
    .build()

Documentation describes setTargetResolution method as follows:

Sets the intended output target resolution.

The target resolution attempts to establish a minimum bound for the image resolution. The actual image resolution will be the closest available resolution in size that is not smaller than the target resolution, as determined by the Camera implementation. However, if no resolution exists that is equal to or larger than the target resolution, the nearest available resolution smaller than the target resolution will be chosen.

Correct me if I am wrong, but if device is able to take photos larger than 1200x1600 (e.g. 3024x4032), the output photo will be at least 1200x1600.

Unfortunately in many devices (e.g. Huawei P20 Pro, Samsung A5) the output photo is significantly smaller than 1200x1600, e.g. 480x640. Notice that these devices are able to take really large photos.

Is my ImageCaptureConfig badly configured or this is a bug?


Solution

  • It could be a bug that have been recently fixed at AOSP. refer https://android.googlesource.com/platform/frameworks/support/+/5c1aed8c4c502a74eb4ee6d30fe2089f4afcaf11