get Camera Picture Rotation - Android android.hardware

Android examples for android.hardware:Camera Rotation

Description

get Camera Picture Rotation

Demo Code

import android.hardware.Camera;
import android.view.Surface;

public class Main {

  static int getPictureRotation(final int rotation, final int cameraId) {
    final Camera.CameraInfo info = new Camera.CameraInfo();
    try {//  ww w .  ja  v a2 s .  c  om
      Camera.getCameraInfo(cameraId, info);
    } catch (Exception e) {
    }
    int degrees = 0;
    switch (rotation) {
    case Surface.ROTATION_0:
      degrees = 0;
      break;
    case Surface.ROTATION_90:
      degrees = 90;
      break;
    case Surface.ROTATION_180:
      degrees = 180;
      break;
    case Surface.ROTATION_270:
      degrees = 270;
      break;
    }

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

}

Related Tutorials