AForge.Imaging.ColorReduction.ColorImageQuantizer.CalculatePalette C# (CSharp) Method

CalculatePalette() public method

Calculate reduced color palette for the specified image.

See CalculatePalette(UnmanagedImage, int) for details.

public CalculatePalette ( Bitmap image, int paletteSize ) : Color[]
image System.Drawing.Bitmap Image to calculate palette for.
paletteSize int Palette size to calculate.
return Color[]
        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 );
            }
        }

Same methods

ColorImageQuantizer::CalculatePalette ( UnmanagedImage image, int paletteSize ) : Color[]

Usage Example

        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;
        }
All Usage Examples Of AForge.Imaging.ColorReduction.ColorImageQuantizer::CalculatePalette