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:
Java code
- @Override
- protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
- switch (resultcode) {
- case 1:
- 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 the URI is empty, so pay special attention to
- Uri Mimagecaptureuri = Data.getdata ();
- //The URI returned is not empty, then 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 URI
- }
- }
- Break ;
- Default:
- Break ;
- }
- }
Second: deal with the 90 degree problem and show:
Java code
- Private void SetImage (Uri mimagecaptureuri) {
- //Whether it is taking pictures or selecting pictures each picture has stored in the data also stored with corresponding rotation angle orientation value
- //So we take out the image is to remove the angle value so that the picture can be displayed correctly, without rotating the effect of viewing
- Contentresolver cr = this.getcontentresolver ();
- cursor cursor = cr.query (Mimagecaptureuri, NULL, NULL, NULL, or null ); From the database based on the URI
- if (cursor! = null) {
- Cursor.movetofirst (); //Move the cursor to the first place because the URI here is the one that contains the ID, so it's the only one that doesn't need to loop.
- String FilePath = cursor.getstring (Cursor.getcolumnindex ("_data")); Get Picture path
- String orientation = cursor.getstring (cursor
- . Getcolumnindex ("orientation")); //Get angle of rotation
- Cursor.close ();
- if (filePath! = null) {
- Bitmap Bitmap = Bitmapfactory.decodefile (FilePath); //Read resource picture according to 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, can also zoom out and so on
- Matrix M = new Matrix ();
- int width = bitmap.getwidth ();
- int height = bitmap.getheight ();
- M.setrotate (angle); //Rotation angle degree
- Bitmap = Bitmap.createbitmap (bitmap, 0, 0, width, height,
- M, true); //New Image generation
- }
- Photo.setimagebitmap (bitmap);
- }
- }
- }
OK to complete, need to take pictures and select the part of the picture function see http://104zz.iteye.com/blog/1687662
Android 90-degree problem rotated when selecting a picture or taking a photo