在HTML5画布上清除线 [英] clear line on HTML5 Canvas

查看:788
本文介绍了在HTML5画布上清除线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法去掉一条线?
在我的画布上,我有一个不透明度为0.5,宽度为20像素的线,让我们说。
现在我想使它更长,意味着从旧的一个绘制另一行。
当这样做时,旧线和新线之间的匹配点变得不太透明(因为它们现在由两条线组成)。

Is there a way to unstroke a line? On my canvas I have a line with opacity 0.5, and width of 20 pixels, let's say. Now I want to to make it longer, means to draw another line right out of the old one. when doing that, the matching points between the old and the new lines become less transparent (because they're made of two lines now). so I want to unstroke the old line and then stroke the new one.

我可以这样做吗?

感谢

推荐答案

如何绘制到画布上是由API严格定义的,软件和/或硬件是由浏览器开发者。一些浏览器使用硬件加速,其他人正在工作atm。 (例如,使用软件渲染器atm)

How you draw to a canvas is strictly defined by the API, but how it is done in software and/or hardware is up to the browser developers. Some of the browser using hardware acceleration and the others are working on it atm. (eg. using a software renderer atm)

在绘图时,在计算机图形绘制中,绘制到缓冲区。当你调用lineTo和stroke时,缓冲区被更新,并且底层像素中的所有信息都会丢失(或者如果你使用透明度,则会丢失部分信息),并且没有办法通过撤销来恢复它(除非有一个包含加载的实现

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时间,但是会大大增加内存

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

这篇关于在HTML5画布上清除线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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