Android provides this code to preview the camera face up for all camera and screen settings:
public static void setCameraDisplayOrientation(Activity activity, int cameraId, android.hardware.Camera camera) { android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay() .getRotation(); 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; } int result; 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; } camera.setDisplayOrientation(result); }
In the simplest case, when the screen is in portrait orientation ( rotation is 0) with a reverse camera, this reduces to result = info.orientation . According to documents, information. Orientation
angle of rotation of the camera image clockwise, so that it is displayed correctly on the display in a natural orientation. It must be 0, 90, 180 or 270.
This means that info.orientation should be the sum that the raw camera images rotate counterclockwise.
On the back of the camera, the Samsung Galaxy S II info.orientation is 90, as expected for reverse cameras. However, the preview of the original camera rotates 90 degrees clockwise, not counterclockwise. This means that after applying the above code, the preview is displayed upside down (180 degrees).
Why is there a 180 degree difference between the information reported by the camera and the actual orientation of its raw images?
This exact problem - the camera images are 90 degrees clockwise, when info.orientation reports 90 - this question is also reported.
Also see this possibly related question .
android android camera
one''
source share