Perfect solution Android Samsung mobile from Gallery Select photo rotation problem _android

Source: Internet
Author: User

Recently solved a problem that has been troubling me for a long time. Samsung mobile phone Photo picture rotation problem, the project has the function of uploading pictures, then involves taking photos, choose pictures from the album, other mobile phones are ok no problem, but Samsung's mobile phone photos, you will be very clear to see the photos will rotate, Then you find the image according to the path has been rotated, the solution finally I found. We can read the image from the path of the photo exif (exchangeable image File interchange images) information in the rotation angle, as for this EXIF can look at Daniel's article

Android under the EXIF

According to the debugging, it can be clearly found that Samsung mobile phone photos of the rotation angle is 90 degrees, while the other mobile phone rotation angle is 0 degrees

Take a look at the code:

/** 
  * Read the rotation angle in the photo EXIF information 
  * @param path photo paths 
  * @return Angle * * Public 
 static int Readpicturedegree ( String path) { 
  int degree = 0; 
  try { 
   Exifinterface exifinterface = new Exifinterface (path); 
   int orientation = Exifinterface.getattributeint (exifinterface.tag_orientation, exifinterface.orientation_normal); 
   Switch (orientation) {case 
    exifinterface.orientation_rotate_90: 
     degree =; 
     break; 
    Case exifinterface.orientation_rotate_180: 
     degree = 180; 
     break; 
    Case exifinterface.orientation_rotate_270: 
     degree = 270; 
     break; 
   } 
  } catch (IOException e) { 
   e.printstacktrace (); 
  } 
  return degree; 
 } 

So we just need to rotate the picture from the angle of rotation.

public static Bitmap Toturn (Bitmap img) { 
  Matrix matrix = new Matrix (); 
  Matrix.postrotate (+90); /* Flip 90 degrees * 
  /int width = img.getwidth (); 
  int height =img.getheight (); 
  img = Bitmap.createbitmap (img, 0, 0, width, height, matrix, true); 
  return img; 
 } 

Easy to solve, isn't it perfect?
The above is the entire content of this article, I hope you like.

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.