Reduces the number of colors in an image.

 

   
Syntax
 
     

[Visual Basic]
Sub ReduceColors(inPlt As Object, inCols As Integer, inDither As Boolean)

[C#]
void ReduceColors(object inPlt, int inCols, bool inDither);

 

   
Params
 
     
Name   Description
inPlt The palette to use for color reduction - see below.
inCols The number of colors that should be used.
inDither Whether to dither the final image.

 

   
Notes
 
     

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. If you want ImageGlue to derive a palette for you then just specify one of the standard Palette parameter string options. Additionally you may need to supply a number of colors for the palette.

If you want to use a palette from a file - typically an act file - then supply the path to that file.

If you want to use a raw palette derived from some other source then provide the raw data. You may obtain such information using the GetInfo method or by reading an act file into memory.

Raw palettes consist of an array of 768 bytes holding 256 RGB triplets. Additionally ImageGlue will handle RGBA data.

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 color reduced canvasses onto other canvasses.

   
See Also
 
     

None.

 

   
Example
 
     

[Visual Basic]
Dim ca As New Canvas
ca.DrawFile(Server.MapPath("rez/birds.jpg"), "")
ca.ReduceColors("grayscale", 64, True)
ca.SaveAs(Server.MapPath("gray.jpg"), "")

[C#]
Canvas ca = new Canvas();
ca.DrawFile(Server.MapPath("rez/birds.jpg"), "");
ca.ReduceColors("grayscale", 64, true);
ca.SaveAs(Server.MapPath("gray.jpg"), "");

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

birds.jpg

gray.jpg