android - Selecting photo from new Google Photos app has incorrect orientation -


i'm trying choose photo using intents on android. works , photos being retrieved photos app (camera, gallery, screenshots etc.. if selected new photos app); except ones backed online on google photos.

photos taken in portrait retrieved in landscape when getting bitmap. have code orientation of photo can translate accordingly, orientation 0 when choosing online photo on new google photos app. ideas on how should orientation these photos 0 being returned? code below - thanks.

starting intent

intent = new intent(intent.action_pick, android.provider.mediastore.images.media.external_content_uri); startactivityforresult(i, import_photo_result); 

intent result

uri selectedimageuri = data.getdata(); imagebitmap = mediastore.images.media.getbitmap(this.getcontentresolver(), selectedimageuri);  //fix rotation int orientation = -1; cursor cursor = mediastore.images.media.query(getcontentresolver(), selectedimageuri, new string[] { mediastore.images.imagecolumns.orientation });  try {     if (cursor.movetofirst()) {         orientation = cursor.getint(0);     } } {     cursor.close(); }  imagebitmap = utils.rotateimagewithrotation(orientation, imagebitmap);  //get stream display , send bytearrayoutputstream stream = new bytearrayoutputstream(); imagebitmap.compress(bitmap.compressformat.jpeg, 70, stream); // byte array here byte[] bytearray = stream.tobytearray(); sendimage(bytearray, null); 

rotate image

public static bitmap rotateimagewithrotation(int rotationindegrees, bitmap mbitmap) {     matrix matrix = new matrix();     if (rotationindegrees != 0f) {         matrix.prerotate(rotationindegrees);     }     bitmap adjustedbitmap = bitmap.createbitmap(mbitmap, 0, 0, mbitmap.getwidth(), mbitmap.getheight(), matrix, true);     return adjustedbitmap; } 

i gave , used amazing library instead. kudos work!

https://github.com/coomar2841/image-chooser-library


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -