After taking the photo, look at the rotation angle, if there is a rotation angle, the description is rotated, and then rotated back with the rotation matrix.
Calling party:
int degree = bitmaputils.getbitmapdegree (File.getabsolutepath ()); Bitmaputils.compressbitmapforuploadlimitmaxsize (This, file, max_upload_size); Bitmaputils.rotatebitmapbydegree (file, degree);
Public Static intgetbitmapdegree (String path) {intdegree = 0; Try { //reads a picture from the specified path and obtains its EXIF informationExifinterface Exifinterface =Newexifinterface (path); //get rotation information for a picture intOrientation =Exifinterface.getattributeint (Exifinterface.tag_orientation, Exifinterface.orientation_normal); Switch(orientation) { CaseExifInterface.ORIENTATION_ROTATE_90:degree= 90; Break; CaseExifInterface.ORIENTATION_ROTATE_180:degree= 180; Break; CaseExifInterface.ORIENTATION_ROTATE_270:degree= 270; Break; } } Catch(IOException e) {e.printstacktrace (); } returndegree; } Public Static voidRotatebitmapbydegree (File file,intdegree) { if(File = =NULL|| !file.exists () | | degree = = 0) { return; } Bitmap Bitmap=NULL, Rotatedbitmap =NULL; Try{bitmap=Bitmapfactory.decodefile (File.getabsolutepath ()); if(Bitmap = =NULL) { return; } //creates a rotation matrix based on the rotation angleMatrix Matrix =NewMatrix (); Matrix.postrotate (degree); //rotate the original image according to the rotation matrix and get a new pictureRotatedbitmap = Bitmap.createbitmap (Bitmap, 0, 0, bitmap.getwidth (), Bitmap.getheight (), Matrix,true); Savebitmap2file (rotatedbitmap, file); } Catch(OutOfMemoryError e) {l.exception (e); } finally { if(Bitmap! =NULL) {bitmap.recycle (); } if(Rotatedbitmap! =NULL) {rotatedbitmap.recycle (); } System.GC (); } }
Samsung mobile Camera Rotation problem