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