get Camera FOV - Android android.hardware

Android examples for android.hardware:Camera Feature

Description

get Camera FOV

Demo Code

import android.hardware.Camera;

public class Main{

    private static Camera sOpenedCamera = null;
    private static float[] fov = null;
    private static Object sAccesLock = new Object();
    public static float[] getCameraFOV() {
        if (fov == null) {
            synchronized (sAccesLock) {
                if (sOpenedCamera != null) {
                    fov = new float[2];
                    fov[0] = sOpenedCamera.getParameters()
                            .getHorizontalViewAngle();
                    fov[1] = sOpenedCamera.getParameters()
                            .getVerticalViewAngle();
                } else {
                    try {
                        Camera camera = Camera.open();
                        fov = new float[2];
                        fov[0] = camera.getParameters()
                                .getHorizontalViewAngle();
                        fov[1] = camera.getParameters()
                                .getVerticalViewAngle();
                        camera.release();
                    } catch (RuntimeException e) {
                        fov = new float[] { 60, 45 };
                    }//w  ww  .  ja v  a 2 s  . c  o m
                }
            }
        }
        return fov;
    }

}

Related Tutorials