小程序生成推广海报

作者:jcmp      发布时间:2021-04-30      浏览量:0
1、getQrcode() {let u

1、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");

2、let cx = 30 + 25

3、let cy = 20 + 25

ctx.arc(cx, cy, 25, 0, 2 * Math.PI);

4、ctx.fill()

5、ctx.clip();

ctx.drawImage(avatar, 30, 20, 52, 52);

6、ctx.save();

ctx.draw(true, function() {

wx.canvasToTempFilePath({

7、x: 0,

8、y: 0,

9、width: 300,

10、height: 350,

11、destWidth: 300,

12、destHeight: 350,

13、canvasId: 'Canvas',

success: function(res) {

14、console.log("结束1")

15、that.setData({

shareImagePath: res.tempFilePath。

16、})

17、},

fail: function(res) {

console.log(res.errMsg)

18、}

19、}, this)

20、});

21、},

ctxText(title, size, color, x, y, align) {

ctx.textAlign = align ? align : 'left';

ctx.setFillStyle(color);

ctx.setFontSize(size);

ctx.fillText(title, x, y);

22、},