In the development of Android applications, you may encounter similar friends in the circle of photos or albums to choose a picture of the scene, take pictures or select pictures in the display when the picture is not the angle, obviously is the vertical version of the picture, showing the absence of lying.
This is because on some specific phones, such as the Samsung series phone, the pre-installed photo album program when viewing the picture will be based on the camera when the phone rotation angle to automatic rotation.
Next, explain how to get the angle of the picture and how to rotate it.
1 /// <summary>2 ///gets the specified path picture shooting angle3 /// </summary>4 /// <param name= "path" ></param>5 /// <returns></returns>6 protectedInt32 getimagerotate (String path)7 {8 varAngle =0;9Exifinterface exif =NULL;Ten Try One { AEXIF =Newexifinterface (path); - } - Catch(Exception ex) the { - } - - if(Exif! =NULL) + { -Angle = exif. Getattributeint (Exifinterface.tagorientation,-1); + if(Angle! =-1) A { at Switch(angle) - { - Case(int) Android.Media.Orientation.Rotate90: -Angle = -; - Break; - Case(int) Android.Media.Orientation.Rotate180: inAngle = the; - Break; to Case(int) Android.Media.Orientation.Rotate270: +Angle = the; - Break; the } * } $ ElseAngle =0;Panax Notoginseng } - returnangle; the}
After you get the angle, it's simple, then rotate the picture.
angle = getimagerotate (path); if (angle! = 0 var m = new Matrix (); var width = bitmap. Width; var height = bitmap. Height; M.setrotate (angle); Bitmap = Bitmap.createbitmap (bitmap, 0 , , width, height, m, true ); }
The next thing to do is to look at your needs.
Xamarin develops Android notes: Take pictures or albums to select picture Angle issues