uni.chooseImage 调整大小
时间: 2024-02-03 18:42:12 浏览: 192
在调用uni.chooseImage方法后,可以获取到选择的图片文件路径。接着,可以使用uni.getImageInfo方法获取图片信息,包括图片的宽高等信息。根据需要,可以根据图片的宽高比例,调整图片的大小。
示例代码如下:
```javascript
uni.chooseImage({
success: function (res) {
uni.getImageInfo({
src: res.tempFilePaths[0],
success: function (info) {
console.log('width:' + info.width)
console.log('height:' + info.height)
// 根据需要,调整图片的大小
var width = info.width
var height = info.height
if (width > 1000) {
height = height * 1000 / width
width = 1000
}
if (height > 1000) {
width = width * 1000 / height
height = 1000
}
console.log('new width:' + width)
console.log('new height:' + height)
}
})
}
})
```
在上述示例中,如果图片的宽度或高度超过了1000像素,则将其等比例缩小至宽度或高度为1000像素。
阅读全文
相关推荐











