Reduces the number of colors in the bitmap.


static void ReduceColors(Bitmap bitmap, ColorPaletteType palette, bool dither);

[Visual Basic]

Shared Sub ReduceColors(bitmap As Bitmap, palette As ColorPaletteType, dither As Boolean)
Name Description
bitmap The bitmap to which the effect should be applied.
palette The palette to use for color reduction.
dither Whether to dither the final image.

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

You can use many formats of palette, see ColorPaletteType. 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 bitmap onto another.



using (Bitmap bm = (Bitmap)Bitmap.FromFile(Server.MapPath("rez/david-bruyndonckx-F_hft1Wiyj8-unsplash.jpg"))) {
  Effects.ReduceColors(bm, new ColorPaletteType(ColorPaletteFamily.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.