Reduces the number of colors on the canvas.


void ReduceColors(XPalette inPalette, int inColors, bool inDither);

[Visual Basic]

Sub ReduceColors(inPalette As XPalette, inColors As Integer, inDither As Boolean)
Name Description
inPalette The palette to use for color reduction.
inColors The number of colors to use.
inDither Whether to dither the final output.

This method allows you to do color reduction on a canvas using a variety of palette, dither and color options.

You can use many formats of palette, see XPalette. Additionally you may need to supply a number of colors for the color reduction.

The dither parameter determines whether dithering is performed when the colors in the image are reduced. ImageGlue uses a highly optimized Floyd-Steinberg diffusion dither for speed and quality.

Please note that video drivers expect that colors like black and white will always be present in an image. ImageGlue may remove these colors if they are not required. This means you may have problems drawing one color reduced canvas onto another.

This operation is only valid for raster images so if the canvas is not in raster format it will be rasterized for you.


[C#]Canvas canvas = new Canvas(Server.MapPath("rez/birds.jpg"));
canvas.ReduceColors(new XPalette(XPalette.PaletteDefinition.Grayscale), 64, true);

[Visual Basic]Dim canvas As New Canvas(Server.MapPath("rez/birds.jpg"))
canvas.ReduceColors(New XPalette(XPalette.PaletteDefinition.Grayscale), 64, True)

The code above reduces the image to 64 level grayscale and then saves it as a JPEG. Two sample images are shown below.