Samsung mobile Camera Rotation problem

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.