Android 90-degree problem rotated when selecting a picture or taking a photo

Source: Internet
Author: User

Because the previous blog post ignored the point content, so fill in here, the following is to solve the photo or select the picture display when the picture rotated 90 degrees or other degrees of problems, so that the photo can be displayed on the front: the following:

First, look directly at the above post to shoot or finish the picture after processing part:

@Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {        Switch(resultcode) { Case1:            if(Data! =NULL) {                //get the returned URI, basically select the photo when the return is in the form of a URI, but in the photo of the machine is empty URI, so pay special attention toUri Mimagecaptureuri =Data.getdata (); //when the URI returned is not empty, the picture information data is obtained in the URI. If it's empty, then we're going to get it in the following way                if(Mimagecaptureuri! =NULL) { setimage(Mimagecaptureuri);//processing and displaying pictures based on URIs                }            }             Break; default:             Break; }    }

Second: deal with the 90 degree problem and show:

    Private void setimage(Uri mimagecaptureuri) {//whether it's a photo shoot or a picture, each picture has a orientation value stored in the data that corresponds to the rotation angle.//so we are taking out the image is to take the angle value out so that the picture can be displayed correctly, no rotation effect to watchcontentresolver CR= This. Getcontentresolver (); Cursor Cursor= Cr.query (Mimagecaptureuri,NULL,NULL,NULL,NULL);//from the database based on the URI        if(Cursor! =NULL) {Cursor.movetofirst ();//move the cursor to the first, because the URI here is the one that contains the ID, so it's the only one that doesn't need a loop to point to the first.StringFilePath= Cursor.getstring (Cursor.getcolumnindex ("_data"));//Get Picture PathString Orientation =cursor.getstring (cursor. Getcolumnindex ("Orientation"));//get the angle of rotationCursor.close (); if(FilePath!=NULL) {Bitmap Bitmap= Bitmapfactory.decodefile (FilePath);//read resource picture from Path                int Angle= 0; if(Orientation! =NULL&& "". Equals (orientation)) { angle =integer.parseint (orientation); }                if(Angle! = 0) {                    //The main function of the following method is to turn the picture to an angle, you can zoom out and so onMatrixm=NewMatrix (); int width=bitmap.getwidth (); int Height=bitmap.getheight (); M.setRotate (angle); //Rotation Angle DegreeBitmap = Bitmap.createbitmap (bitmap, 0, 0, width, height, m,true);//Create a new image} photo.setimagebitmap (bitmap); }        }    }

Android 90-degree problem rotated when selecting a picture or taking a photo

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.