简体   繁体   English

画布中的擦除功能

[英]erase functionality in canvas

I need to erase the contents of my canvas. 我需要擦除画布上的内容。 I can achieve this by using 'globalCompositeOperation = "destination-out"'. 我可以通过使用'globalCompositeOperation =“ destination-out”'来实现。 I have already stored the draw coordinates in my json object, but after erasing I need to update my json object. 我已经将绘制坐标存储在json对象中,但是在擦除之后,我需要更新json对象。 I tried to capture it's x,y co-ordinate on mouse move (while erasing). 我试图在鼠标移动时(擦除时)捕获它的x,y坐标。 Then I matched the same with my previous store object and updated the same. 然后,将其与以前的商店对象匹配并更新了相同对象。 But it's quite a big procedure which causes degradation in my performance. 但这是一个很大的过程,会导致性能下降。 Is there any other way to do it? 还有其他方法吗?

This will clear all contents of your canvas. 这将清除画布的所有内容。 (Assuming that ctx is your context, and width and height are the width and height of your canvas. (假设ctx是您的上下文,而width和height是画布的宽度和高度。

ctx.clearRect(0, 0, width, height)

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

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