The steps are as follows:
1. The angle at which the picture file is rotated is read first:
/** * Read the rotation angle of the picture file through the Exifinterface class * @param path: path to the picture file * @return The image file's rotated angle */public static int readpicdegree (String p ATH) {int degree = 0;//reads the picture file information class Exifinterfaceexifinterface Exif = null;try {exif = new exifinterface (path);} catch (Ioex Ception e) {//TODO auto-generated catch Blocke.printstacktrace ();} if (exif! = null) {int orientation = Exif.getattributeint (exifinterface.tag_orientation,exifinterface.orientation_ Switch (orientation) {Case ExifInterface.ORIENTATION_ROTATE_90:degree = 90;break;case ExifInterface.ORIENTATION_ROTATE_180:degree = 180;break;case ExifInterface.ORIENTATION_ROTATE_270:degree = 270; Break;}} return degree;}
2. Pass the above angle as a parameter to the following function correction:
/** * Correct the picture to the correct direction * * @param degree: The angle of the picture being rotated by the system * @param bitmap: Picture to correct direction * @return Reverse image */public static bitmap rot Atebitmap (int degree, Bitmap Bitmap) {Matrix matrix = new Matrix (); matrix.postrotate (degree); Bitmap BM = bitmap.createbitmap (Bitmap, 0, 0, bitmap.getwidth (), Bitmap.getheight (), Matrix, true); return BM;}
Android Pictures with rotation