Search code examples
androidandroid-cameraxpinchzoom

How to support wide angle zoom using CameraX API?


I have an app where I use CameraX to create a custom camera. Currently only default back camera is supported but I need to access wide angle lens now to provide zoom out below 1.0. I have seen lot of questions regarding the same in stack overflow, but nothing helped me. I tried out solution from Android CameraX How to implement Wide Angle / Zoom Out but when I execute the code, the control doesn't even go inside addCameraFilter method of CameraSelector.Builder. Do I need to switch to Camera2 to achieve zoom out below 1.0 or can I do it using Camerax itself? is yes how?


Solution

  • The solution mentioned in the link would work, but it is partial solution. Few points to take care of while working with CameraX are,

    1. Before switching the camera to wide lens, don't set zoom ratio.
    2. Restart the camera when camera switch needed.
    3. Rebuild preview whenever camera is restarted.
    4. Set zoom ratio once camera is restarted.

    If device supports wide lens usage to third party apps, then just doing above should work. I believe you wouldn't require to switch to Camera2.