Android examples for android.hardware:Camera Rotation
get Required Rotation for Camera
import android.app.Activity; import android.content.Context; import android.content.pm.PackageManager; import android.hardware.Camera; import android.view.Surface; public class Main{ public static int getRequiredRotation(Camera cam, Activity act, int camId, boolean preview) { Camera.CameraInfo camInfo = new Camera.CameraInfo(); Camera.getCameraInfo(camId, camInfo); int deviceRotation = act.getWindowManager().getDefaultDisplay() .getRotation();//from w w w . j a va2 s . c om int deviceAngle = 0; switch (deviceRotation) { case Surface.ROTATION_0: deviceAngle = 0; break; case Surface.ROTATION_90: deviceAngle = 90; break; case Surface.ROTATION_180: deviceAngle = 180; break; case Surface.ROTATION_270: deviceAngle = 270; break; } int result; if (preview) { //rotate result = (camInfo.orientation + deviceAngle) % 360; //account for front-camera mirroring result = (360 - result) % 360; } else { result = (camInfo.orientation + deviceAngle) % 360; } return result; } }