微信小程序 canvas 绘制圆形状
page({
// 绘制canvas
drawCanvas:function(){
const ctx = wx.createCanvasContext('poster')
// 画圆形二维码
this.circleImg(ctx,this.data.canvasLotteryQR, 151.5, 535.5, 36) // (canvas对象,二维码图片本地路径(如果是网络图片先用wx.downloadFile存本地),坐标x, 坐标y, 半径)
},
// 圆形图片
circleImg: function (ctx, img, x, y, r){
ctx.save()
var d = 2 * r;
var cx = x + r;
var cy = y + r;
ctx.arc(cx, cy, r, 0, 2 * Math.PI);
ctx.clip();
ctx.drawImage(img, x, y, d, d);
ctx.restore()
},
})