简体   繁体   English

如何在 html 5 画布中删除区域的剪辑

[英]How to remove the clip of a region in html 5 canvas

I am working with clip() in canvas.我正在画布中使用clip()

I have made a region to clip() , as specified below我已经为clip()创建了一个区域,如下所示

this.svgRenderer.ctx.rect(positionX, positionY, Width, Height);
this.svgRenderer.ctx.clip();

After few drawing on the same canvas, I am trying to remove the clip for that region by using save() and restore() .在同一画布上绘制几次之后,我尝试使用save()restore()删除该区域的剪辑。

But I am making mistakes and can't get that.但我犯了错误,无法理解。 So suggest any other way to remove the clip for the specified region without using save() and restore()所以建议任何其他方法来删除指定区域的剪辑,而不使用save()restore()

.clip is a permanent context state change. .clip是永久的上下文状态更改。

It can only be removed by wrapping it in .save and .restore .它只能通过将其包装在.save.restore中来删除。

ctx.save();
ctx.clip(); // assuming the clipping path was already declared
// draw whatever needs to be clipped
ctx.restore(); // reset the clipping region
               // (and any other attributes that have been modified since .save())

Changing the canvas element width will clear the context state (and remove clipping) but will also erase the existing drawings.更改画布元素宽度将清除上下文状态(并删除剪辑),但也会删除现有绘图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM