See CalculatePalette(UnmanagedImage, int) for details.
public Color[] CalculatePalette( Bitmap image, int paletteSize ) { BitmapData data = image.LockBits( new Rectangle( 0, 0, image.Width, image.Height ), ImageLockMode.ReadOnly, image.PixelFormat ); try { return CalculatePalette( new UnmanagedImage( data ), paletteSize ); } finally { image.UnlockBits( data ); } }
private Bitmap reducedColor(Bitmap image, int numColors) { // create color image quantization routine ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer()); // create 16 colors table Color[] colorTable = ciq.CalculatePalette(image, numColors); // create dithering routine FloydSteinbergColorDithering dithering = new FloydSteinbergColorDithering(); dithering.ColorTable = colorTable; // apply the dithering routine Bitmap newImage = dithering.Apply(image); return newImage; }