1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 微信小程序海报功能(canvas)- - -附效果图

微信小程序海报功能(canvas)- - -附效果图

时间:2018-12-23 09:06:28

相关推荐

微信小程序海报功能(canvas)- - -附效果图

效果图如下所示

.wxml

<canvas canvas-id="shareBox"></canvas>

.wxss

canvas{width: 100%;height: 100vh;overflow: hidden;}

.js

Page({data: {deviceWidth:'',deviceHeight:'',},onShow:function(e){//绘制canvas图片var that = this;var imgLogo = '/images/userprofile.png'; //微信头像本地路径var bgimg = "/images/mastergraph.png"; //背景图var qrcode = "/images/qrcode.png";//二维码const ctx = wx.createCanvasContext('shareBox', this);ctx.setFillStyle("white");var deviceWidth = that.data.deviceWidth; //宽var deviceHeight = that.data.deviceHeight; //高ctx.fillRect(0, 0, deviceWidth, deviceHeight);// 绘制背景图ctx.drawImage(bgimg, 10, 10, deviceWidth - 20, deviceHeight - 110);//绘制底部背景颜色ctx.setFillStyle('#fff')ctx.fillRect(0, deviceHeight - 100, deviceWidth, 100);//绘制微信名称ctx.setFontSize(15);ctx.setFillStyle('#000');ctx.setTextAlign('left');ctx.fillText("林晨:", 110, deviceHeight - 55);//绘制分享标题ctx.setFontSize(15);ctx.setFillStyle('#000');ctx.setTextAlign('left');ctx.fillText("邀请您一起参加", 110, deviceHeight - 35);// 绘制二维码ctx.drawImage(qrcode,deviceWidth - 100, deviceHeight - 90, 80, 80);//绘制圆形头像ctx.save();ctx.beginPath();ctx.arc(60, deviceHeight - 50, 35, 0, 2 * Math.PI, false);ctx.setStrokeStyle('#eee')ctx.stroke(); //画了背景的话要先画圆在裁剪才能有圆形图片ctx.clip(); //裁剪ctx.drawImage(imgLogo, 20, deviceHeight - 85, 80, 80);ctx.restore();ctx.draw(); },onLoad: function (options) {let that = thiswx.getSystemInfo({success(res) {console.log(res.windowWidth);console.log(res.windowHeight);that.setData({deviceWidth: res.windowWidth,deviceHeight: res.windowHeight,})}})},})

海报如果在真机上不显示可以参考:/qq_43764578/article/details/101704775

对你有帮助的话记得收藏点赞,有什么问题欢迎评论留言。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。