0

I am using the Java Google Drive API in Android Studio to download an image from the drive:

OutputStream outputStream = new FileOutputStream(mContext.getFilesDir() + "/" + destPath); 
mDriveService.files().get(id).executeMediaAndDownloadTo(outputStream);

Most images get saved normally on the device (like the original on drive). But some images get saved rotated.

What I mean is, for example, I have a photo on google drive which is orientated in portrait mode. But after the code above downloads it on the device, the photo on the device is in landscape mode.

  • How about file size (in bytes) of original and copy? – blackapps Mar 24 '21 at 05:24
  • `the photo on the device is in landscape mode.` Where do you see it displayed? By which app? – blackapps Mar 24 '21 at 05:26
  • Apparently the downloaded image is not rotated when downloaded, but it gets rotated while doing this: Bitmap myBitmap = BitmapFactory.decodeFile(tmpImgFile.getAbsolutePath()); imageView.setImageBitmap(myBitmap); – Thomas Suditu Mar 24 '21 at 05:53

1 Answers1

2

I found out the problem was actually not saving the image, but the way I was looking at the image (because I was displaying it in an ImageView as a Bitmap). While doing decodeFile, the image was getting rotated.

For that, the solution I used is here: Android: Bitmaps loaded from gallery are rotated in ImageView