简体   繁体   English

如何在Java中编写抗锯齿程序

[英]How to program anti-aliasing in Java

I have implement the Bresenham Algorithm for a Simple line drwaing class, and now i want to set a anti-aliasing over it, I use JavaFX for the viewing. 我已经为一个简单的行drwaing类实现了Bresenham算法,现在我想对其设置反锯齿,我使用JavaFX进行查看。

How can i implement a anti-aliasing without using library´s ? 如何在不使用库的情况下实现抗锯齿?

One way to do anti-aliasing is to use oversampling. 进行抗锯齿的一种方法是使用过采样。 The image is rendered in a higher solution, where typically for efficiency and ease of implementation the generated image is larger by a factor which is a power of two. 在更高的解决方案中渲染图像,在通常情况下,为了提高效率和易于实施,生成的图像将放大2倍。 The resulting image is then downsampled. 然后对生成的图像进行下采样。

A more efficient way (which has some drawbacks on the other hand) is the algorithm by Wu . Wu算法是一种更有效的方法(另一方面,它也有一些缺点)。 In this approach, a lookup table is used which stores the desired coloring for adjacent pixels in which a pixel is plotted using sub-pixel accuracy. 在这种方法中,使用查找表,该查找表存储了使用子像素精度绘制像素的相邻像素所需的颜色。 Bresenham's line algorithm then uses this lookup table to place a pixel with actual sub-pixel accuracy. 然后,Bresenham的线算法使用此查找表来放置具有实际子像素精度的像素。

The latter approach does not require downsampling and potentially fewer memory accesses, however atrifacts might show up if lines cross as the second line cancels out the pixels plotted for the first line. 后一种方法不需要下采样,并且可能不需要更多的内存访问,但是,如果第二条线交叉而抵消了为第一条线绘制的像素,则可能会出现无义感。 This effeced can be remedied by using saturated addition for the pixels instead of replacement. 可以通过对像素使用饱和添加而不是替换来解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM