getQrcode() {
let userinfo = that.data.userinfo;
let avatar = that.data.avatar;
let qrcode = that.data.qrcode;
let username = userinfo.nickname;
let id = "ID:" + userinfo.id;
ctx.setFillStyle('#FFFFFF')
ctx.fillRect(0, 0, 300, 350);
ctx.drawImage(qrcode, 75, 100, 150, 150);
that.ctxText(username, 14, '#000', 100, 40);
that.ctxText(id, 12, '#8b8b8b', 100, 65);
that.ctxText("分享好友,获取收益!", 12, '#9d9d9d', 150, 300, "center");
that.ctxText("【微信小程序】", 12, '#333333', 150, 320, "center");
let cx = 30 + 25
let cy = 20 + 25
ctx.arc(cx, cy, 25, 0, 2 * Math.PI);
ctx.fill()
ctx.clip();
ctx.drawImage(avatar, 30, 20, 52, 52);
ctx.save();
ctx.draw(true, function() {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 300,
height: 350,
destWidth: 300,
destHeight: 350,
canvasId: 'Canvas',
success: function(res) {
console.log("结束1")
that.setData({
shareImagePath: res.tempFilePath
})
},
fail: function(res) {
console.log(res.errMsg)
}
}, this)
});
},
ctxText(title, size, color, x, y, align) {
ctx.textAlign = align ? align : 'left';
ctx.setFillStyle(color);
ctx.setFontSize(size);
ctx.fillText(title, x, y);
},