微信小游戏——绘制圆形微信头像

直接上代码:

ctx.save() //保存上下文
ctx.beginPath()//开始绘制
ctx.arc(screenWidth / 10, screenHeight / 7, 24, 0, 2 * Math.PI, false)//画一个圆
ctx.clip()//裁剪这个圆
ctx.drawImage(image, screenWidth / 10 - 25, screenHeight / 7 - 25, 50, 50)//将图片绘制进圆
ctx.restore()//恢复上下文  接下来可以进行其他绘制操作

效果图:

猜你喜欢

转载自blog.csdn.net/ling_cmd/article/details/81216356