canvas裁剪

clip(),在画布内使用路径,只绘制该路径内所包含区域的图像,不会只路径外的图像。

var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');

context.arc(160,160,150,0,2*Math.PI);
context.fillStyle = '#fff';
context.fill();
context.clip();

context.fillStyle = 'rgba(280,187,186,1)';
context.fillRect(10,10,300,300);//显示半径为150的粉色圆

 

posted @ 2017-10-12 23:19  corn林  阅读(210)  评论(0编辑  收藏  举报