Java tutorial
//package com.java2s; //License from project: GNU General Public License import android.app.Activity; import android.hardware.Camera; import android.util.DisplayMetrics; import android.view.Surface; import android.util.Log; public class Main { private static final String TAG = "BACKGROUND_VID_OVERLAY"; static final int NO_CAMERA = -101; static int calculateOrientation(Activity activity, int cameraId) { if (cameraId == NO_CAMERA) return 0; DisplayMetrics dm = new DisplayMetrics(); Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int cameraRotationOffset = info.orientation; Log.w(TAG, "cameraRotationOffset = " + cameraRotationOffset); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int currentScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Log.w(TAG, "currentScreenRotation = " + currentScreenRotation); int degrees = 0; switch (currentScreenRotation) { 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; } Log.w(TAG, "degrees = " + degrees); int orientation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { orientation = (cameraRotationOffset + degrees) % 360; orientation = (360 - orientation) % 360; } else { orientation = (cameraRotationOffset - degrees + 360) % 360; } Log.w(TAG, "orientation = " + orientation); return orientation; } }