白癜风有那些特征 http://m.39.net/pf/a_4834283.html
最近朋友圈里经常有看到这样的头像既然这么火,大家要图又这么难,作为程序员的自己当然要自己动手实现一个。老规矩,先看效果图

仔细研究了下,发现实现起来并不难,核心代码只有下面10行。

wx.canvasToTempFilePath({x:0,y:0,width:num,height:num,destWidth:num,destHeight:num,canvasId:shareImg,success:function(res){that.setData({prurl:res.tempFilePath})wx.hideLoading()},fail:function(res){wx.hideLoading()}})一,首先要创建一个小程序

至于如何创建小程序,我这里就不在细讲了,我也有写过创建小程序的文章,也有路过相关的学习视频,去翻下我历史文章找找就行。

二,创建好小程序后,我们就开始来布局

布局很简单,只有下面几行代码。

!--画布大小按需定制这里我按照背景图的尺寸定的--canvascanvas-id="shareImg"/canvas!--预览区域--viewclass=previewimagesrc={{prurl}}mode=aspectFit/imagebuttonsize=miniopen-type="getUserInfo"bindgetuserinfo="shengcheng"data-k="1"生成头像1/buttonbuttonsize=miniopen-type="getUserInfo"bindgetuserinfo="shengcheng"data-k="2"生成头像2/buttonbuttonsize=miniopen-type="getUserInfo"bindgetuserinfo="shengcheng"data-k="3"生成头像3/buttonbuttonsize=miniopen-type="getUserInfo"bindgetuserinfo="shengcheng"data-k="4"生成头像4/buttonbuttontype=primarybindtap=save保存分享图/button/view

实现效果图如下

三,使用canvas来画图

其实我们实现



转载请注明地址:http://www.hongqisx.com/hqls/9811.html