简体   繁体   中英

On Android - how to capture image/video from the wide angle camera?

How to capture images or videos from the camera2 api wide angle camera? or the telescopic camera? I know how to handle camera capture for front & back camera. I just can't understand how to open the camera and choose the wide/telescopic camera?

I guess it has something to do with setting one of the following :

CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA
CameraCharacteristics.getPhysicalCameraIds()
CameraCharacteristics.getAvailablePhysicalCameraRequestKeys()
CameraDevice.createCaptureSession(SessionConfiguration config)
CameraCharactersitics.LOGICAL_MULTI_CAMERA_SENSOR_SYNC_TYPE

But I fail to understand the scenario of setting it up and I didn;t find any good explanation. I will appreciate any kind of tutorial or explanation. Last question - how to test it with no phsical device? I mean - how to setup the Avd/emulator?

So I asked this on the CameraX discussion group and here is the reply from google:

For CameraX to support wide angle cameras we are working with manufacturers to expose those via camera2 first. Some devices indeed do so today in an non-determinstic manner. Will keep you posted as we progress, thanks!

So, If somebody still looks for the answer: Almost no manufacturer supported that until android 10. from android 10 - all physical camera are logical cameras. It means that you can see those cameras on

manager.getCameraIdList()

you will get a list of all available camera, just look for the CameraCharacteristics.LENS_FACING direction. and populate a list.

Here is the full code:

public CameraItem[] GetCameraListFirstTime() {
    List<CameraItem> listValuesItems = new ArrayList<CameraItem>();
    boolean IsMain = false;
    boolean IsSelfie = false;
    if(manager == null)
        manager = (CameraManager)mContext.getSystemService(CAMERA_SERVICE);
    try {

        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics chars = manager.getCameraCharacteristics(cameraId);
            if (!IsMain && chars.get(CameraCharacteristics.LENS_FACING) == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                listValuesItems.add(new CameraItem(Integer.parseInt(cameraId), "Main"));
                IsMain = true;
            }
            else if (!IsSelfie && chars.get(CameraCharacteristics.LENS_FACING) == Camera.CameraInfo.CAMERA_FACING_BACK) {

                    listValuesItems.add(new CameraItem(Integer.parseInt(cameraId), "Selfie"));
                    IsSelfie = true;
            }
            else
                listValuesItems.add(new CameraItem(Integer.parseInt(cameraId), "Wide or Other"));
        }

    }
    catch (CameraAccessException e) {
        Log.e(TAG, e.toString());

    }
    return listValuesItems.toArray(new CameraItem[0]);
}

public class CameraItem implements java.io.Serializable{
public int Key;
public String Description;
public CameraItem(int key, String desc)
{
    Key=key;
    Description = desc;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM