androidzoomingandroid-cameraxlenses

Zoom with the telephoto lens with CameraX


In my app, zooming is limited to the main lens instead of the telephoto lens of the device(if there is one).

The telephoto lens could be provided by any manufacturer; I do not wish to implement an API specific to a manufacturer's device to access the telephoto or wide angle lens.

This results in less optimal pictures, and the app cannot zoom further then the main camera's zoom limits.

How do I use the telephoto lens (and wide angle lens as well if possible) to zoom in my app?

Thanks.


Solution

  • CameraX is simply not capable of giving you the camera/lens you wish/need. You can set the zoom level to minimum available and hope for the best. You can try Camera2 but it is also not guaranteed.
    In theory, If you set zoom ratio to something below 1.0f, this should make cameraX to use wide angle camera. In reality, I have never seen any device apart from Pixel 6 supporting this. Even Google Pixel are not capable of implementing necessary features to support 3rd party camera apps with CameraX. In case you want to check, this is how you can set minimum available zoom: In most devices you will see minimum zoom is 1.0f while in Pixel 6 it was ~0.7f.

    val maxAvailableZoom = camera?.cameraInfo?.zoomState?.value?.maxZoomRatio
    val minAvailableZoom = camera?.cameraInfo?.zoomState?.value?.minZoomRatio ?: 1f
    camera?.cameraControl?.setZoomRatio(minAvailableZoom)