html2canvas微信头像后,微信小程序使用canvas在真机上不显示用户头像问题(不显示网络图片)...

如果要做一个分享朋友圈,而需要通过canvas绘制图片,在真机上是不显示你的用户头像的,但是开发者工具和真机上打开调试是可以看的。这就需要在微信公众平台把你头像前面的网址配置到downloadFile网址里去

比如下面的头像,就需要把https://wx.qlogo.cn添加到downloadFile网址去,然后清除缓存,重新打开就可以看到绘制的头像了

"avatarUrl":"https://wx.qlogo.cn/mmopen/vi_32/F8sadfIasdasdfadf"},还有这个头像地址需要下载到本地才能去绘制openfun() {      let that= this;      wx.downloadFile({        url: that.data.avatarUrl,        success: function (res) {          // console.log(res.tempFilePath);          that.setData({            avatarUrl:res.tempFilePath,          })          //绘图方法          that.drawImage();        }, fail: function (fres) {        }      })    },    //绘制方法    drawImage:function() {      var that = this      const ctx = wx.createCanvasContext('sharePhoto',this)      // console.log(wx.getSystemInfoSync())      var Width = wx.getSystemInfoSync().windowWidth*0.74      var Height = wx.getSystemInfoSync().windowHeight * 0.68      var avatarUrl = that.data.avatarUrl      ctx.save();      ctx.beginPath();      ctx.arc(Width * 0.5, Height * 0.175, Width * 0.098, 0, 2 * Math.PI);      ctx.clip();//画了圆 再剪切      ctx.drawImage(avatarUrl, Width * 0.4, Height * 0.109, Width*0.197, Height*0.132)      ctx.restore();      ctx.save();      ctx.draw();    },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值