怎么可以获得图片的大小? (不是尺寸!)

小程序 文章 2020-09-07 17:41 560 0 全屏看文

AI助手支持GPT4.0

怎么可以获得图片的大小? (不是尺寸!)How can I get the size of the picture? (Not the size!)

怎么可以获得图片的大小? (不是尺寸!)

调用imgSecCheck 时说是图片大小限制为1m,所以前端想在调用前检查图片是否超过1m, 如果超过了1m 就使用wx.compressImage 接口按比例压缩图片。 那么问题来了,怎么样才能获取到图片的大小呢? 查了一下没有找到呢。

这个图片不是选择或者是拍照的图片,是通过canvas 处理过导出的图片

When imgseccheck is called, the image size is limited to 1m, so the front end wants to check whether the image exceeds 1m before calling. If it exceeds 1m, it will be used wx.compressImage Interface to compress pictures proportionally. So the question is, how can we get the size of the image? I checked it and didn't find it. This image is not selected or photographed. It is exported through canvas

回答:

鲁诚:


uni.downloadFile({

url: '图片地址',

success (bigRes) {    console.log(bigRes)  wx.getFileInfo({     filePath: bigRes.tempFilePath,     success (res) {         console.log(res.size)        console.log(res.digest)     }   })  },  fail (err) {    console.log('err', err)   } })


Lunatic.:谢谢呢。解决了。
断片:

wx.chooseImage的success回调函数中的res.tempFiles是上传图片本地临时文件列表,里面有size属性

Lunatic.:这个图片不是选择得到的图片呢,是通过canvas 处理之后导出的图片。
断片:toDataURL导出的吗
Lunatic.:嗯,看到方法了呢,解决了!
จุ๊บ:

选择图片的时候,返回了本地临时文件的大小,单位B

-EOF-

AI助手支持GPT4.0