Android Image rotation

Source: Internet
Author: User

Photos are sometimes rotated by the system, and the corrective steps are as follows:

1. The angle at which the picture file is rotated is read first:

/** * Read the image file's rotation angle through the Exifinterface class * @param path: The path to the picture file * @return The image file's rotated angle*/     Public Static intreadpicdegree (String path) {intdegree =0; //class Exifinterface to read picture file informationExifinterface exif =NULL; Try{EXIF=Newexifinterface (path); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }        if(Exif! =NULL) {            intOrientation =Exif.getattributeint (exifinterface.tag_orientation, Exifinterface.orientation_            NORMAL); Switch(orientation) { CaseExifInterface.ORIENTATION_ROTATE_90:degree= -;  Break;  CaseExifInterface.ORIENTATION_ROTATE_180:degree= the;  Break;  CaseExifInterface.ORIENTATION_ROTATE_270:degree= the;  Break; }        }        returndegree; }

2. Pass the above angle as a parameter to the following function correction:

    /** * To correct the picture in the right direction * * @param degree: The angle of the picture being rotated by the system * @param bitmap: Picture to correct the direction * @return Straighten backward picture */     Public StaticBitmap Rotatebitmap (intdegree, Bitmap Bitmap) {Matrix Matrix=NewMatrix ();        Matrix.postrotate (degree); Bitmap BM= Bitmap.createbitmap (Bitmap,0,0, Bitmap.getwidth (), Bitmap.getheight (), Matrix,true); returnBM; }

Android Image rotation

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.