您好啊,我使用 downloadFile 或是 getImageInfo 转成本地还是画不出来呀,求教.
好了,还是我自己发现问题了,然后楼主的问题,我在 2.0.8 版没有出现,也许是腾讯自己加白名单了吧,那个链接,下载不同步画图,还有指向问题都是造成大家的网络图片画不出来,我借楼主的地方放个代码,画出网络图片,谢谢。
drawPage: function () {
var that = this; //这个要保存起来,给下面 context.draw(true, that.getTempFilePath);使用
var context = wx.createCanvasContext('share');
var avatar = this.data.avatar;
this.setData({
canvasSwitcher: true
})
wx.downloadFile({
url: avatar,
success: function (res) {
if(res.tempFilePath) {
context.drawImage(res.tempFilePath, 150, 260, 30, 30);
context.draw(true, that.getTempFilePath);
}
}
})
var images = '../images/Bitmap.png';
context.setFillStyle('#f2f2f2');
context.drawImage(images, 10, 10, 295, 250);
console.log(avatar)
context.setFontSize(20);
context.setFillStyle("#666");
context.fillText('232', 230, 380);
context.fillText('累积完成', 200, 400);
context.fill();
context.draw(true, this.getTempFilePath);
},
getTempFilePath:function(){
console.log(121221)
wx.canvasToTempFilePath({
canvasId: 'share',
success: (res) => {
this.setData({
shareTempFilePath: res.tempFilePath
})
}
})
},
应为网络图片下载要花时间,所以不同步,不想等就请画别的 draw 的第一个参数写 true
今天重新修正,上线后发现图片保存不了,确实是要把头像下载地址加到白名单,被坑到了。