admin管理员组文章数量:1026966
Using javascript, I've drawn several polygon images on my canvas.
I'd like to, based on user events/clicks, be able to clear a section of the canvas (one of those polygon images), which is an irregular shape, not a rectangle.
So, I cannot use clearRect() for my purpose.
Can anyone think of a way I can do that?
Essentially, I'd like to make a portion of my canvas transparent, but it is not a rectangular shape... Once I have an area defined with which I can fill() and stroke(), can I not also clear() it... I know that such a function is not available. What are folks doing to clear irregularly shaped sections?
I'm a little new to this, so apologies in advance if this sounds like a silly question.
Using javascript, I've drawn several polygon images on my canvas.
I'd like to, based on user events/clicks, be able to clear a section of the canvas (one of those polygon images), which is an irregular shape, not a rectangle.
So, I cannot use clearRect() for my purpose.
Can anyone think of a way I can do that?
Essentially, I'd like to make a portion of my canvas transparent, but it is not a rectangular shape... Once I have an area defined with which I can fill() and stroke(), can I not also clear() it... I know that such a function is not available. What are folks doing to clear irregularly shaped sections?
I'm a little new to this, so apologies in advance if this sounds like a silly question.
Share Improve this question asked May 16, 2012 at 21:53 Boriana DitchevaBoriana Ditcheva 2,01516 silver badges26 bronze badges1 Answer
Reset to default 9Use ctx.clip()
to define the current stroke as a clipping region.
See https://developer.mozilla/en/Canvas_tutorial/Compositing
I also created a demo at http://jsfiddle/alnitak/6ABp7/
The clipping path is part of the graphics state, so you can .save()
the previous state, set clipping, draw some more stuff, and then .restore()
the original state.
Using javascript, I've drawn several polygon images on my canvas.
I'd like to, based on user events/clicks, be able to clear a section of the canvas (one of those polygon images), which is an irregular shape, not a rectangle.
So, I cannot use clearRect() for my purpose.
Can anyone think of a way I can do that?
Essentially, I'd like to make a portion of my canvas transparent, but it is not a rectangular shape... Once I have an area defined with which I can fill() and stroke(), can I not also clear() it... I know that such a function is not available. What are folks doing to clear irregularly shaped sections?
I'm a little new to this, so apologies in advance if this sounds like a silly question.
Using javascript, I've drawn several polygon images on my canvas.
I'd like to, based on user events/clicks, be able to clear a section of the canvas (one of those polygon images), which is an irregular shape, not a rectangle.
So, I cannot use clearRect() for my purpose.
Can anyone think of a way I can do that?
Essentially, I'd like to make a portion of my canvas transparent, but it is not a rectangular shape... Once I have an area defined with which I can fill() and stroke(), can I not also clear() it... I know that such a function is not available. What are folks doing to clear irregularly shaped sections?
I'm a little new to this, so apologies in advance if this sounds like a silly question.
Share Improve this question asked May 16, 2012 at 21:53 Boriana DitchevaBoriana Ditcheva 2,01516 silver badges26 bronze badges1 Answer
Reset to default 9Use ctx.clip()
to define the current stroke as a clipping region.
See https://developer.mozilla/en/Canvas_tutorial/Compositing
I also created a demo at http://jsfiddle/alnitak/6ABp7/
The clipping path is part of the graphics state, so you can .save()
the previous state, set clipping, draw some more stuff, and then .restore()
the original state.
本文标签: javascriptIs there a way to clear a nonrectangular area in a canvas elementStack Overflow
版权声明:本文标题:javascript - Is there a way to clear a non-rectangular area in a canvas element? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745648585a2161173.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论