About Android in call system take pictures, return picture is rotated 90 degrees

Source: Internet
Author: User



Reprinted blog: http://blog.csdn.net/walker02/article/details/8211628



A problem encountered in the development of the project, Samsung mobile phone photos in the selection of images appear abnormal, the study found that should be mobile phone shots of the picture rotated 90 degrees, some pictures rotated 180 degrees, some phones are normal. In the forum found a method, you can get the properties of the picture, read the picture rotation angle.


/**
     * Read image properties: angle of rotation
     * @param path image absolute path
     * @return degree angle of rotation
     */
    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;
    }
   /*
    * Rotate the picture
    * @param angle
    * @param bitmap
    * @return Bitmap
    */
   Public static Bitmap rotaingImageView(int angle , Bitmap bitmap) {
       //Rotate the image Action
       Matrix matrix = new Matrix();;
       matrix.postRotate(angle);
       System.out.println("angle2=" + angle);
       // Create a new image
       Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
               bitmap.getWidth(), bitmap.getHeight(), matrix, true);
       Return resizedBitmap;
   } 





About Android in call system take pictures, return picture is rotated 90 degrees


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.