圆形头像
//绘制圆形图片
drawCricleImg(ctx, url, x, y, width, height){
var avatarurl_width = width;
var avatarurl_heigth = height;
var avatarurl_x = x;
var avatarurl_y = y;
ctx.save();
ctx.beginPath();
ctx.arc(avatarurl_width / 2 + avatarurl_x, avatarurl_heigth / 2 + avatarurl_y, avatarurl_width / 2, 0, Math.PI * 2, false);
ctx.clip();
ctx.drawImage(url, avatarurl_x, avatarurl_y, avatarurl_width, avatarurl_heigth);
ctx.restore();
},
圆形带边框头像
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();
}
网友评论