Contents Previous Next

### 10.18.1 Enabling anti-aliased lines

Anti-aliased lines are enabled by calling the method SetAntiAliasing() in the Image class in the script where you want to use anti-aliasing.

The anti-aliasing for lines works by "smoothing" out the edges on the line by using a progressive scale of colors interpolated between the background color and the line color.

Note: The algorithm used for anti-aliasing of lines is quite simple. It would be possible to achieve even better result by doing some real 2D signal processing. However, doing real time 2D signal processing on a HTTP server would be foolish so the design is deliberately kept simple. To achieve best visual result always use a dark line color on a light background.

An example will show that this, quite simple algorithm, gives a reasonable good result. The figures below shows a radar plot with and without anti-aliasing.

Figure 170: Spiderplot without anti-aliasing [src]

Figure 171: Spiderplot with anti-aliasing [src]

One thing you need to keep in mind when deciding to use anti-aliasing is that it could have potentially a dramatic effect on the time it takes to generate the image. Line drawing with anti-aliasing turned on is roughly 8 times slower than the normal line drawing so treat this feature wisely.

Furthermore there are a couple of "gotchas" you should be aware of when using anti-aliasing.

1. Anti-aliased lines uses up more of the available color-palette. The exact number of colors used is dependent on the line-angle, a near horizontal or near vertical line uses more colors (number of lines with different angles uses more colors). Hence it might not be possible to use anti-aliasing with color-gradient fill since the number of available colors in the palette might not be enough. A normal palette can keep around 256 colors. This means that you are advised to use a true-color image when using anti-aliasing.
2. Anti-aliasing does not work very well together with background images since it assumes a the same solid color on each side of the line. Doing a more advanced anti-aliasing algorithm would simple take to much processing power.
3. Anti-aliased lines will ignore the line width specified. They will always have a width of roughly 1.

Contents Previous Next