Android Pictures with rotation

Source: Internet
Author: User

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

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.