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

Source: Internet
Author: User
Tags rotate image


Due to the needs of the project, there is no custom camera function, just call the system's camera program. But there is a problem, that is, the photo is finished to show the picture is actually rotated pictures ....


Workaround:

/**
                  * Get the rotation angle of the picture, some systems rotate the picture taken, and some do not rotate
                  */
                 Int degree = readPictureDegree(f.getAbsolutePath());
                  
                 BitmapFactory.Options opts=new BitmapFactory.Options();//Get the thumbnail display to the screen opts.inSampleSize=2;
                 Bitmap cbitmap=BitmapFactory.decodeFile(f.getAbsolutePath(),opts);
                  
                 /**
                  * Rotate the picture to a positive direction
                  */
                 Bitmap newbitmap = rotaingImageView(degree, cbitmap);
                 iv.setImageBitmap(newbitmap);
/** * 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 image * @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;
 }


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.



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


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.