封装的微信小程序canvas绘制带有边框的圆形头像;注意url不能为网络图片,如果是请配合wx.getImageInfo()获取腾讯临时地址;
drawCircle(ctx, width, height, x, y, url, radio) {
//第一个参数:创建的画布对象
//第二个参数:矩形的宽
//第三个参数:矩形的高
//第四个参数:矩形左上角x轴坐标点,
//第五个参数:矩形左上角y轴坐标点,
//第六个参数:绘制的图片的URL
//第七个参数:设备缩放比
ctx.save();
ctx.arc(width / 2 + x, height / 2 + y, width / 2 + 5 * radio, 0, Math.PI * 2, false);
ctx.setFillStyle('#fff')
ctx.fill()
ctx.clip();
ctx.beginPath();
ctx.arc(width / 2 + avatarurl_x, height / 2 + y, width / 2, 0, Math.PI * 2, false);
ctx.clip();
ctx.drawImage(url, x, y, width, height);
ctx.restore();
}