电脑怎么画线?
Windows GDI 具有以下函数:
MoveTo();
线到();
它们接受开始绘图和停止绘图的坐标。
但这些功能是如何实现的呢? (尤其是LineTo)
他们需要计算A点和B点之间的所有点吗?
这条线具体是怎么画的??
Windows GDI has these functions:
MoveTo();
LineTo();
They accept coordinates where to start drawing and where to stop drawing.
But how are these functions implemented?? (especially LineTo)
Do they need to calculate all points between point A and point B??
How is this line drawn exactly??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,他们计算 A 和 B 之间的每个单独的点。
有效地执行此操作的最常见方法称为 布雷森纳姆直线算法。
请注意,Windows LineTo 不会绘制最后一个点。当一条一条地绘制线段时,这可以防止端点被重复绘制。
Yes, they calculate each individual point between A and B.
The most common way to do this efficiently is known as Bresenham's Line Algorithm.
Note that Windows LineTo does not draw the last point. When line segments are drawn one after another, this prevents the endpoints from being double drawn.
没有看过 Windows 源代码的人可以深入回答这个问题......
但是 Windows 与任何其他软件一样:它需要某种算法来画一条线...您可以在此处看到一种这样的算法 http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
Moveto 更“简单”,因为它只更新系统知道的当前坐标 的...
nobody who never saw the Windows source code can answer this in-depth...
BUT Windows is just as any other software: it needs some algorithm to draw a line... one such algorithm you can see here http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
The Moveto is "easier" in that it just updates the current coordinates the system know of...
它不需要计算 A 和 B 之间的所有点(无限),而只需要计算 A 和 B 之间的离散像素。这通常是标准线光栅化算法。请参阅 Wikipedia 了解 Bresenham 的线光栅化算法,这是标准的教科书示例,通常是基础用于更灵活的光栅化算法。
It doesn't need to calculate all points between A and B (which are infinite) but only the discrete pixels between A and B. That's usually a standard line rasterization algorithm. See Wikipedia for Bresenham's line rasterization algorithm, which is the standard school book example and usually the base for more flexible rasterization algorithms.
我怀疑除了布雷森汉姆(Bresenham)之外还有更多的事情发生,因为还有(可选)抗锯齿功能。请参阅本文了解可能实现的算法(Xiaolin Wu 的直线算法)
I suspect there is more going on that just (a form of) Bresenham as there is also (optional) anti-aliasing. see this article for what might be the implemented algoritm (Xiaolin Wu's line algorithm)