如何从画布中只删除一条线,而不是所有的图纸? [英] How to delete only a line from the canvas, not all the drawings?

查看:129
本文介绍了如何从画布中只删除一条线,而不是所有的图纸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现的解决方案是清除整个画布,但我只想删除一条线而不是画布上的所有绘图。

The solution I found is to clear the whole canvas, but I only want to delete one line not all drawings on the canvas.

我该怎么办?

推荐答案

没有简单的方法来做,因为像素的以前的信息丢失后你绘制任何东西。
这里有一个更好的答案:在HTML5画布上清除行

There's no simple way to do that, as the previous information of the pixels are lost after you draw anything. Here you've a better answer: clear line on HTML5 Canvas


在绘图时在计算机图形绘制中,绘制到缓冲区。和
当你调用lineTo和笔画缓冲区更新,所有的
信息,在底层的像素丢失(或部分
丢失,如果你使用透明度),没有办法得到它由
撤销(除非有一个实现包含旧的
图纸,但是这将是非常重的内存)。

In computer graphics when drawing something, you draw to a buffer. And when you call lineTo and stroke the buffer is updated and all information that were in the underlying pixels are lost (or partly lost if you use transparency) and there is no way to get it back by undoing (unless there is an implementation containing loads of old drawings, but that would be really heavy for the memory).

因此,为了能够撤消一个笔划可以节省大量的CPU / GPU时间BUT
会大大增加内存

So to be able to undo a stroke might save alot of CPU/GPU time BUT whould heavily increase the memory

唯一的办法似乎是使用clearRect。

So the only way seems to use clearRect.

这篇关于如何从画布中只删除一条线,而不是所有的图纸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆