uni-app应用使用uni.getImageInfo获取照片信息时纵向照片长宽相反问题(纵向照片长宽相反,横向长宽正确 小米10和1+8)
uni-app应用使用uni.getImageInfo获取照片信息时纵向照片长宽相反问题(纵向照片长宽相反,横向长宽正确 小米10和1+8)
产品分类:
uniapp/App
PC开发环境操作系统:
Windows
PC开发环境操作系统版本号:
10
HBuilderX类型:
正式
HBuilderX版本号:
3.1.12
手机系统:
Android
手机系统版本号:
Android 10
手机厂商:
小米
手机机型:
Mi10、1+8等
页面类型:
vue
打包方式:
云端
项目创建方式:
HBuilderX
示例代码:
uni.getImageInfo({
src: url,
success: (res) => {
// #ifdef H5
const {width,height,path} = res
resolve({width,height,path})
// #endif
// #ifdef MP-WEIXIN || APP-PLUS
const {width,height,path,type} = res
resolve({width,height,path,type})
console.log('res:'+res)
console.log('orientation:'+res.orientation)
console.log('width:'+res.width)
console.log('height'+res.height)
// #endif
},
fail: (error) => {
reject(error)
}
})
```
### 操作步骤:
- 小米10竖直拍照,uni.getImageInfo获取图片长宽。
### 预期结果:
- 图片信息结果,长宽相反。
### 实际结果:
- 结果符合预期。
### bug描述:
1. 使用小米10和1+8纵向垂直拍照,App应用使用uni.getImageInfo获取照片信息,照片方向是正常的,但是width和height是相反的。
2. 横向拍照,照片方向是正常的,width和height也正常。
所以 无法判断照片的长和宽是对的,还是相反的, 无法正确二次编辑保存照片.
更多关于uni-app应用使用uni.getImageInfo获取照片信息时纵向照片长宽相反问题(纵向照片长宽相反,横向长宽正确 小米10和1+8)的实战教程也可以访问 https://www.itying.com/category-93-b0.html
4 回复
同样的问题,怎么都没人回答
更多关于uni-app应用使用uni.getImageInfo获取照片信息时纵向照片长宽相反问题(纵向照片长宽相反,横向长宽正确 小米10和1+8)的实战教程也可以访问 https://www.itying.com/category-93-b0.html
到现在居然还有这个问题
到现在还有这个问题哈哈哈哈
这是一个典型的EXIF方向信息处理问题。在Android设备上,某些厂商(如小米、一加)拍摄的纵向照片会包含EXIF方向标记,但实际像素数据仍保持传感器采集方向。
uni.getImageInfo返回的width/height是图片的原始像素尺寸,未考虑EXIF方向信息。当设备竖拍时,传感器输出的原始数据可能是横向的,需要通过orientation字段判断实际方向。
解决方案:
- 检查返回的orientation字段,如果不为"up"(即非1),说明图片需要旋转
- 根据orientation值交换宽高:
uni.getImageInfo({
src: url,
success: (res) => {
let {width, height, orientation} = res
if (orientation && orientation !== 'up') {
// 需要旋转时交换宽高
[width, height] = [height, width]
}
console.log('校正后宽高:', width, height)
}
})

