let bgUrl = ''
// canvas绘制网络图片需保存至本地
wx.getImageInfo({
src: '',//服务器返回的图片地址
success: function (res) {
console.log(res);
bgUrl = res.Path
},
fail: function (res) {
console.log(res);
}
});
ctx.drawImage(bgUrl, 0, 0, wigth, height);
wx.getImageInfo({
src: 'https://云存储的下载地址/signin/signin_01.png?sign=031a219531cc9a146d34f18cef76ac0a&t=1616849572',//服务器返回的图片地址
success: function (res) {
bgUrl = res.Path
ctx.drawImage(bgUrl, 0, 0, wigth, height);
ctx.save();
},
fail: function (res) {
console.log(res);
}
});
wx.getImageInfo 是异步调用啊,你这图片信息还没获取到就开始绘制了,当然绘制不出来了。 wx.getImageInfo({ src: '',//服务器返回的图片地址 success: function (res) { console.log(res); bgUrl = res.Path ctx.drawImage(bgUrl, 0, 0, wigth, height); }, fail: function (res) { console.log(res); } }); 这样再试试