来自 Google Drive Android Studio API 的图像被旋转

Posted

技术标签:

【中文标题】来自 Google Drive Android Studio API 的图像被旋转【英文标题】:Image from Google Drive Android Studio API gets rotated 【发布时间】:2021-06-20 18:50:31 【问题描述】:

我在 android Studio 中使用 Java Google Drive API 从驱动器下载图像:

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

大多数图像都能正常保存在设备上(就像驱动器上的原始图像一样)。但有些图片会旋转保存。

我的意思是,例如,我在谷歌驱动器上有一张以纵向模式定向的照片。但是上面的代码下载到设备上后,设备上的照片是横向的。

【问题讨论】:

原件和复印件的文件大小(以字节为单位)如何? the photo on the device is in landscape mode. 你在哪里看到它显示?通过哪个应用程序? 显然下载的图像在下载时没有旋转,但在执行此操作时会旋转: Bitmap myBitmap = BitmapFactory.decodeFile(tmpImgFile.getAbsolutePath()); imageView.setImageBitmap(myBitmap); 【参考方案1】:

我发现问题实际上不是保存图像,而是我查看图像的方式(因为我在 ImageView 中将其显示为位图)。 在执行 decodeFile 时,图像正在旋转。

为此,我使用的解决方案在这里: Android: Bitmaps loaded from gallery are rotated in ImageView

【讨论】:

以上是关于来自 Google Drive Android Studio API 的图像被旋转的主要内容,如果未能解决你的问题,请参考以下文章