机型:HUAWEI nova 3e,微信版本:7.0.3
chooseLocalImage: function (e) {
var that = this;
let idx = e.currentTarget.dataset.idx
//console.log(idx)
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'], //尺寸
sourceType: ['album', 'camera'], //来源
success(res) {
var _tempUrl = res.tempFilePaths[0];
that.data.rate = 2000000 / res.tempFiles[0].size //不超过2M
//console.log(that.data.rate)
wx.getImageInfo({
src: _tempUrl,
success(res) {
that.setData({
height: parseInt(that.data.width * res.height / res.width),
imageCanvasshow: false
});
const ctx = wx.createCanvasContext('imagecanvas');
let _width = that.data.width
let _height = that.data.height
ctx.drawImage(_tempUrl, 0, 0, _width, _height);
ctx.draw()
setTimeout(() => {
that.drawLocalImageAfter(idx);
}, 200);
}
})
},
fail: function () {
// fail
},
complete: function () {
// complete
}
})
},
drawLocalImageAfter: function (idx) {
try {
var that = this;
wx.canvasToTempFilePath({
quality: that.data.rate,
width: that.data.width,
heght: that.data.height,
fileType: 'jpg',
canvasId: 'imagecanvas',
success: function (res) {
var _url = that.data.sellerImageUrl
_url[idx] = res.tempFilePath
console.log(res.tempFilePath)
console.log(_url);
that.setData({
sellerImageUrl: _url,
imageCanvasshow: true
});
},
fail: function (err) {
console.log(err);
}
})
}
catch (err) {
console.log(err)
}
},
真机上调试时,第一次报canvasToTempFilePath:fail:illegal arguments,第二次正常,第三次报canvasToTempFilePath:fail:illegal arguments,第四次正常,以此类推,最近才开始出现这个问题,有谁知道为什么吗?
微信小程序开发问题解答
微信小程序开发者回答:
麻烦提供出现问题的机型和微信版本,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
本文网址:http://www.91bianli.com/weixinxiaochengxu/5102.html