Android:图片上传到Firebase后旋转-90度
创始人
2024-10-13 20:01:01
0

这个问题可能是由于图片的方向信息不正确导致的。为了解决这个问题,你可以尝试使用 ExifInterface 类来从图片中获取方向信息,并旋转它以使其正常显示。在上传图片之前,可以尝试对图片进行修复,代码示例如下:

// Get the BitmapFactory options object.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

// Decode the file to get the info about it.
BitmapFactory.decodeFile(filePath, options);

// Get the orientation of the image from the Exif data.
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

// Calculate the sample size to use for decoding the image.
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

// Decode the file again, setting the sample size.
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);

// Rotate the bitmap according to the orientation.
bitmap = rotateBitmap(bitmap, orientation);

// Upload the rotated bitmap to Firebase.
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
byte[] data = outputStream.toByteArray();
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReference();
StorageReference imageRef = storageRef.child("images/" + filename);
UploadTask uploadTask = imageRef.putBytes(data);

其中 calculateInSampleSize()rotateBitmap() 这两个方法的实现与正常使用时一样,这里不再赘述。

相关内容

热门资讯

微乐小程序真的有挂!小程序微乐... 微乐小程序真的有挂!小程序微乐辅助器ios(开挂)器-竟然关于是有挂在进入软件靠谱后,参与本局比赛的...
微乐小程序真的有挂!微信微乐自... 微乐小程序真的有挂!微信微乐自建房辅助工具(开挂)插件-好像推荐是有挂1、模拟器是什么优化,俱乐部是...
微信小程序微乐破解器!微信微乐... 微信小程序微乐破解器!微信微乐辅助(开挂)app-真是了解真的有挂暗藏猫腻,小编详细说明破解器有用吗...
微乐小程序黑科技免费!微乐小程... 微乐小程序黑科技免费!微乐小程序多功能修改器(开挂)教程-原来教你真的是有挂1、上手简单,内置详细流...
微乐小程序透视辅助!微乐小程序... 微乐小程序透视辅助!微乐小程序黑科技辅助工具2026最新推荐(开挂)工具-真是科普是有挂1、让任何用...
微乐小程序透视辅助!微乐麻将脚... 微乐小程序透视辅助!微乐麻将脚本透视(开挂)器-原来有挂真的有挂1、起透看视 辅助软件价格2、随意选...
微乐小程序黑科技!广西微乐小程... 微乐小程序黑科技!广西微乐小程序控制器(开挂)教程-确实揭露真的有挂1、打开软件启动之后找到中间准星...
微乐小程序透视挂!微乐自建房免... 微乐小程序透视挂!微乐自建房免费黑科技下载苹果(开挂)神器-切实必备真的有挂1、辅助器安装包、辅助器...
微信小程序微乐破解器!微乐江苏... 微信小程序微乐破解器!微乐江苏自建房辅助app(开挂)插件-本来透视存在有挂进入游戏-大厅左侧-新手...
微乐小程序透视挂!微乐宁夏小程... 微乐小程序透视挂!微乐宁夏小程序插件(开挂)教程-确实了解是真的挂1)有没有挂:进一步探索有辅助吗大...