https://developers.weixin.qq.com/s/KvG7bFmu71AL 代码片段,必需真机调试,开发工具无法运行
wx.compressImage重复压缩图片?wx.compressImage重复压缩图片至指定大小,压一次后就没办法继续压 [图片] compressImage(src, limit) { return new Promise((resolve, reject) => { wx.compressImage({ src: src, quality:70, success: (res) => { console.log('compress', res) wx.getFileSystemManager().getFileInfo({ filePath: res.tempFilePath, success: (img) => { if(img.size<limit*1024){ console.log('img1',img) return resolve({done:true, value:res}) }else{ console.log('img2',img) return resolve({done:false, value:res}) } }, fail: (img) => { console.log('img', img) reject(img) } }) }, fail: (res) => { console.log('error') reject(res) } }) }).then((res) => { if (res.done) { console.log('img1', res) return Promise.resolve(res) } else { console.log('img2', res) return this.compressImage(res.value.tempFilePath, limit) } }).catch((err) => { return Promise.reject(err) }) },
2022-07-11