get Camera FOV (Field of view) - Android Camera

Android examples for Camera:Camera Attribute

Description

get Camera FOV (Field of view)

Demo Code


//package com.java2s;
import android.hardware.Camera;

public class Main {
    private static Object sAccesLock = new Object();
    private static Camera sOpenedCamera = null;
    private static float[] fov = null;

    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 w  w.  j a  v  a 2  s. c  o  m*/
                }
            }
        }
        return fov;
    }
}

Related Tutorials