有没有办法将不透明度设置为画布中的0,而不是用颜色绘制?
我有以下功能:
function draw(event) {
context.beginPath();
context.lineWidth = 20;
context.lineCap = 'round';
context.strokeStyle = 'rgb(255, 255, 255)';
context.moveTo(coord.x, coord.y);
reposition(event);
context.lineTo(coord.x, coord.y);
context.stroke();
}
我想知道是否有可能(而不是在震动中具有颜色),而是将不透明度降低到0,以便我本质上是“擦除”帆布元素并显示出的元素后面。
很抱歉,如果以前有人问过,我在任何地方都找不到任何答案。
I have the following function:
function draw(event) {
context.beginPath();
context.lineWidth = 20;
context.lineCap = 'round';
context.strokeStyle = 'rgb(255, 255, 255)';
context.moveTo(coord.x, coord.y);
reposition(event);
context.lineTo(coord.x, coord.y);
context.stroke();
}
And I would like to know if it's possible to, instead of having a color in the strokeStyle, to just reduce the opacity to 0 so that I am essentially "erasing" the canvas element and show the element that is behind it.
I am sorry if this has been asked before, I couldn't find any answer to this anywhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您需要将GlobalComposeporation设置为一种操作类型,该操作类型在画出画布上时会删除现有颜色。
的小提琴: https://jsfiddle.net/twc1xern/
我做了一个说明这一点 画布,一个在另一个面前。前画布充满红色,后帆布设置为蓝色。设置操作时:
绘制一条线从前景画布上删除颜色数据,显示下面的蓝色画布。
To do this, you need to set the globalCompositeOperation to an operation type that removes the existing colors when something is drawn to the canvas.
I've made a fiddle that demonstrates this: https://jsfiddle.net/twc1xern/
It has two canvases, one in front of the other. The front canvas is filled with red and the back canvas is set to blue. When the operation is set:
Drawing a line removes the color data from the foreground canvas, showing the blue canvas underneath.