This example describes the solution to the problem of rotation in the preview screen when calling camera in Android programming. Share to everyone for your reference, specific as follows:
When calling camera write applications, the front and back camera situations are sometimes different. Sometimes, obviously after the camera is no problem, and call to the front camera, but reversed 180°, or other angles, baffled. After looking at the Android source, found that its solution is very good, then put a source code for future viewing.
public static int getdisplayrotation (activity activity) {int rotation = Activity.getwindowmanager (). Getdefaultdisplay (
). Getrotation ();
Switch (rotation) {case Surface.ROTATION_0:return 0;
Case Surface.ROTATION_90:return 90;
Case Surface.ROTATION_180:return 180;
Case Surface.ROTATION_270:return 270;
return 0; public static void setcameradisplayorientation (activity activity, int cameraid, Camera Camera) {//* Android.ha Rdware.
Camera.setcameradisplayorientation for//documentation.
Camera.camerainfo info = new Camera.camerainfo ();
Camera.getcamerainfo (Cameraid, info);
int degrees = getdisplayrotation (activity);
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);
}
Just call Setcameradisplayorientation when you call camera.
I hope this article will help you with the Android program.