Samsung mobile phone photo, select photo rotation from the image library to solve the problem perfectly, SamSung mobile phone Image Library

Source: Internet
Author: User

Samsung mobile phone photo, select photo rotation from the image library to solve the problem perfectly, SamSung mobile phone Image Library

Recently, I have solved a headache for a long time, that is, Samsung's mobile phone camera image rotation problem. The project has the image upload function, which involves taking photos and selecting images from the album, there is no problem with other mobile phones, but after taking a photo of Samsung's mobile phone, you will clearly see that the photo will be rotated, and then the picture you find Based on the path is already rotated, the solution was finally found by me. We can read the rotation angle in the exif (Exchangeable Image File interchangeable Image File) Information Based on the Image path.

According to the debugging, we can clearly find that the rotation angle of the pictures taken by Samsung mobile phones is 90 degrees, while that of other mobile phones is 0 degrees.

Take a look at the Code:

/ **
      * Read the rotation angle in photo exif information
      * @param path photo path
      * @returnangular
      * /
     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 = 90;
                     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 only need to rotate the image according to the rotation angle.

public static Bitmap toturn (Bitmap img) {
         Matrix matrix = new Matrix ();
         matrix.postRotate (+90); / * Rotate 90 degrees * /
         int width = img.getWidth ();
         int height = img.getHeight ();
         img = Bitmap.createBitmap (img, 0, 0, width, height, matrix, true);
         return img;
}  


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.