get Camera Display Orientation - Android android.hardware

Android examples for android.hardware:Camera Orientation

Description

get Camera Display Orientation

Demo Code

import android.hardware.Camera;

public class Main {

  public static int getDisplayOrientation(int degrees, int cameraId) {
    // See android.hardware.Camera.setDisplayOrientation for
    // documentation.
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    int result;/* ww  w . ja v a 2  s  . c  o m*/
    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;
    }
    return result;
  }

  public static int getDisplayOrientation(int degrees) {
    // See android.hardware.Camera.setDisplayOrientation for
    // documentation.
    Camera.CameraInfo info = new Camera.CameraInfo();
    return (info.orientation - degrees + 360) % 360;
  }

}

Related Tutorials