好吧,我环顾四周,找到了一个代码,它可以让我成功地在画布上绘制一个圆圈,并将该圆圈用作我的图像的蒙版。
代码如下所示:(对于我不知道的真正创建者来说是 codus)
var ctx = document.getElementById('your_canvas').getContext("2d");
ctx.arc(100,100, 50, 0, Math.PI*2,true); // you can use any shape
ctx.clip();
var img = new Image();
img.addEventListener('load', function(e) {
ctx.drawImage(this, 0, 0, 200, 300);
}, true);
img.src="/path/to/image.jpg";
假设我想要 5 个不同的圆圈,所有圆圈都有不同的图像,并且每个圆圈的位置都不同。
有人知道 id 是怎么做的吗?