具有“重放”功能的 HTML5 绘图特征”
我正在尝试实现一个 html5 绘图应用程序。目前,我可以允许保存绘制的图像。我希望能够有一个重播功能,以与最初绘制图像相同的方式重新绘制图像,几乎就像是视频一样。有什么想法吗?
I am trying to implement a html5 drawing app. Currently, I can allow for a drawn image to be saved. I want to be able to have a replay feature that redraws the image the same way that it was originally drawn almost as if it were a video. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Canvas 没有 joni 所建议的 DOM 树。 Canvas 绘制像素,因此在绘制单个对象后您无法检索或移动它们。
您可以使用 canvas.getImageData() 将帧保存到数组中,然后使用 canvas.putImageData() 以相同的顺序恢复这些帧。虽然我不确定它在大画布尺寸下的表现如何。
样本:
Canvas doesn't have a DOM tree as joni suggests. Canvas draws pixels, so you cannot retrieve or move single objects after you've drawn them.
You could save a frame using canvas.getImageData() to an array, and then later restore these frames in the same order, using canvas.putImageData(). Although I'm not sure how well that performs with a big canvas size.
Sample:
我认为任何导致绘制到画布的操作都只需保存在有序数组中即可。
然后您可以单步遍历数组并重复。
I would think that any action that results in drawing to the canvas you simply save in an ordered array.
You can then step through the array and repeat.