请教引擎大佬,我在用原生的canvas实现一些小功能
用了原生的canvas API,但是这个属性我一直不明白 ctx.globalCompositeOperation = “destination-in”;
这个效果,我用来做裁剪,我的代码是:
但是最后的效果是:
我通过ctx.save() 保存了上下文状态,为什么下方还是受了影响,
按照我的理解,这两个CANVAS 都应该绘制出来的,互不影响
我把代码贴在这里
function drawLogo() {
ctx.save();
ctx.beginPath();
ctx.fillStyle = "#fff"
ctx.font = "60px 微软雅黑";
ctx.textAlign = 'center';
ctx.textBaseline = "middle";
ctx.fillText("CANVAS", width / 2, height / 2);
ctx.globalCompositeOperation = "destination-in";
ctx.arc(width / 2, height / 2, 150, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
ctx.restore();
ctx.save();
ctx.beginPath();
ctx.fillStyle = "#fff"
ctx.font = "60px 微软雅黑";
ctx.textAlign = 'center';
ctx.textBaseline = "middle";
ctx.fillText("CANVAS", width / 2 + 150, height / 2 + 150);
ctx.globalCompositeOperation = "destination-in";
ctx.arc(width / 2 + 150, height / 2 + 150, 150, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
ctx.restore();
}

