Android examples for Camera:Camera Orientation
calculate Camera Display Orientation
import android.content.Context; import android.content.res.Configuration; import android.hardware.Camera; import android.util.Log; import android.view.OrientationEventListener; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; public class Main{ public static int calculateCameraDisplayOrientation(int cameraId, int deviceOrientation) { if (deviceOrientation == OrientationEventListener.ORIENTATION_UNKNOWN) { return OrientationEventListener.ORIENTATION_UNKNOWN; }//w ww .j ava 2s . c o m Camera.CameraInfo cameraInfo = getCameraInfo(cameraId); final int rounded = Rounding.roundToMultiplesOf(90, deviceOrientation); int result; if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (cameraInfo.orientation + rounded) % 360; result = (360 - result) % 360; } else { result = (cameraInfo.orientation - rounded + 360) % 360; } return result; } public static Camera.CameraInfo getCameraInfo(int cameraId) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); return cameraInfo; } }