HTML5 中的橡皮筋
我希望在画布上绘制一个矩形,但拉伸起点。但我如何擦除在此过程中绘制的先前矩形。我的意思是,如果我的背景颜色是红色,并且我想在其上绘制一个黑色矩形。在擦除橡皮筋期间绘制的中间矩形时,我希望保留背景。
I wish to draw a rectangle on my canvas but stretching the start point. but how do i erase the previous rectangles drawn during the process. I mean if my background color is red and i want to draw a black rectangle over it. while erasing the intermediate rectangles drawn during rubber banding, i wish to retain the background.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个问题有点难以理解,但我假设您想要使用 getImageData 和 putImageData 执行以下操作:
The question is a little hard to understand, but I'm assuming what you want to do is the following using
getImageData
andputImageData
:您需要重新绘制黑色矩形先前占据的背景部分。重新绘制整个背景可能会更简单。
You need to redraw the portion of the background the black rectangle previously occupied. It may be simpler to just redraw the entire background.
您只需跟踪要绘制的每个对象,并在每一帧中重新绘制其中的每个对象。
您可以稍微优化该过程,但是您必须跟踪绘制的每个内容,以便可以重新绘制。
You simply have to keep track of every single object you want to draw and redraw every single one of them each frame.
You can optimize the process a bit, but you must keep track of each thing drawn so you can redraw.