Example usage for android.hardware Camera getCameraInfo

List of usage examples for android.hardware Camera getCameraInfo

Introduction

In this page you can find the example usage for android.hardware Camera getCameraInfo.

Prototype

public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) 

Source Link

Document

Returns the information about a particular camera.

Usage

From source file:Main.java

public static int HasFrontCamera() {
    int numberOfCameras = Camera.getNumberOfCameras();
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == CAMERA_FACING_FRONT) {
            return i;
        }/*  w  ww  .  java 2s  . c  o m*/
    }
    return 2;
}

From source file:Main.java

public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;/*from www .j  a  v  a  2  s  .  c o  m*/
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360; // compensate the mirror
    } else { // back-facing
        result = (info.orientation - degrees + 360) % 360;
    }
    Log.d(TAG, "camera display orientation: " + result);
    camera.setDisplayOrientation(result);

    return result;
}

From source file:Main.java

public static int getBackCameraId() {
    if (backCameraId == -1) {
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        for (int i = 0; i < getCameraNumber(); i++) {
            Camera.getCameraInfo(i, cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                backCameraId = i;//from  www  . j  a  va  2 s  . c  o  m
                break;
            }
        }
    }
    return backCameraId;
}

From source file:Main.java

public static void setCameraDisplayOrientation(Context mContext, int cameraId, Camera camera) {
    CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    int rotation = ((Activity) mContext).getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;//from ww  w  . j a va 2  s  .  c  o m
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360; // compensate the mirror
    } else { // back-facing
        result = (info.orientation - degrees + 360) % 360;
    }
    camera.setDisplayOrientation(result);
}

From source file:Main.java

public static int getFrontCameraId() {
    if (frontCameraId == -1) {
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        for (int i = 0; i < getCameraNumber(); i++) {
            Camera.getCameraInfo(i, cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                frontCameraId = i;/* w  w w  . ja va2s.c o  m*/
                break;
            }
        }
    }
    return frontCameraId;
}

From source file:Main.java

private static Camera.CameraInfo getCameraInfo() {
    Camera.CameraInfo info = new Camera.CameraInfo();
    for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
        Camera.getCameraInfo(i, info);
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            break;
        }//from w  w  w .ja v a2  s.  c  o  m
    }
    return info;
}

From source file:Main.java

public static int getDisplayOrientationForCamera(Context context, int cameraId) {

    final int DEGREES_IN_CIRCLE = 360;
    int temp = 0;
    int previewOrientation = 0;

    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, cameraInfo);

    int deviceOrientation = getDeviceOrientationDegree(context);
    return previewOrientation;

}

From source file:Main.java

public static int findBackFacingCamera() {
    int cameraId = INVALID_CAMERA_ID;
    // Search for the front facing camera
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            Log.d("CameraUtil", "Camera found");
            cameraId = i;/* www  . j ava2s  .c  o  m*/
            break;
        }
    }
    return cameraId;
}

From source file:Main.java

public static int findFrontFacingCamera() {
    int cameraId = INVALID_CAMERA_ID;
    // Search for the front facing camera
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            Log.d("CameraUtil", "Camera found");
            cameraId = i;//from w ww. ja  va  2  s . c o m
            break;
        }
    }
    return cameraId;
}

From source file:Main.java

static int getCameraId(int position) {
    // Find the total number of cameras available
    int mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the back-facing ("default") camera
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < mNumberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == position)
            return i;
    }/*  ww  w.j av  a2  s  . c  o  m*/

    return NO_CAMERA;
}