0

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?

Droid
  • 45
  • 6
  • See : https://stackoverflow.com/questions/70143720/zoom-with-the-telephoto-lens-with-camerax Also, keep in mind that not every device gives access to wide angle camera. If you hard code a camera Id with camera2, it is very likely it will only work for limited amount of devices. – Orcun Jul 05 '23 at 09:18
  • @Orcun that answer is almost 2 years ago, so I was wondering whether they added any support later in cameraX. I have done my coding in cameraX already and then post release we got this wide angle lens requirement. Now I am worried that will I have to change entire Camera implementation to Camera2 just to support this wide angle camera. – Droid Jul 05 '23 at 09:25
  • I am afraid the situation is more or less same and switching to Camera2 is not going to save you. Many devices do not let 3rd party devs, access to wide angle camera. Unless you are going to run your app in a specific device that you know gives access, you are out of luck. For that reason, CameraX cannot give you wide angle camera access out of box. Because it is not going to work in most devices. Is this a hard requirement? If not go with CameraX and set zoom to below 1f. If device supports you use it.If not, main camera's minimum zoom it is. – Orcun Jul 05 '23 at 09:30
  • @Orcun our main targetted users are using samsung mobiles and in which itself I am unable to set zoom below 1.0 where as in pixel device it works. It is actually an important requirement for users. They were able to use native camera in old app and now in new app only custom camera. – Droid Jul 05 '23 at 09:37
  • I understand. Default camera apps do have access to wide angle camera of the device. Their package names are whitelisted for this access. Some Samsung devices I have, for example Samsung Tab S7, support wide angle camera access. I use Camera2 for enumerating the available cameras on device and calculate FOV for each. Then select the camera with highest FOV. But, If you want an app that would work on a wide range of devices, I would definitely suggest CameraX. In any case, you will never have full access to all cameras in all devices. At least you would keep your sanity. :) – Orcun Jul 05 '23 at 09:49
  • @Orcun So basically if the device allows all cameras to be accessed, then cameraX will do the job. If it doesnt then even camera2 also cant help. Please correct me if i m wrong. – Droid Jul 05 '23 at 10:30
  • yes, that's correct. – Orcun Jul 05 '23 at 10:34
  • @Orcun thanks a lot for your help. Just want to know 1 more thing, do u have any idea how we can apply to get our package whitelisted? I saw that net.sourceforge.opencamera is whitelisted, so like that is it possible to white my app package as well? – Droid Jul 05 '23 at 11:10
  • Unless you root the device, you cannot make anything about it I am afraid. You can use their package name for your app on your tests to see If you can access to wide angle camera. Every device vendor has their own whitelist. Not sure if it is possible to apply to them to get yourself whitelisted. – Orcun Jul 06 '23 at 09:39
  • @Orcun I tried changing my package name to net.sourceforge.opencamera as its whitelisted. But still same result. I wonder is it my code issue. – Droid Jul 06 '23 at 09:59
  • Got it. Maybe try with camera2 and see if you can see wide angle camera. – Orcun Jul 06 '23 at 13:05

1 Answers1

0

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.

andro-girl
  • 7,989
  • 22
  • 71
  • 94