AForge.Imaging.ColorReduction.OrderedColorDithering.Apply C# (CSharp) Method

Apply() public method

Perform color dithering for the specified image.
Unsupported pixel format of the source image. It must 24 or 32 bpp color image.
public Apply ( Bitmap sourceImage ) : Bitmap
sourceImage System.Drawing.Bitmap Source image to do color dithering for.
return System.Drawing.Bitmap
        public Bitmap Apply( Bitmap sourceImage )
        {
            BitmapData data = sourceImage.LockBits( new Rectangle( 0, 0, sourceImage.Width, sourceImage.Height ),
                ImageLockMode.ReadOnly, sourceImage.PixelFormat );

            Bitmap result = null;

            try
            {
                result = Apply( new UnmanagedImage( data ) );
                if ( ( sourceImage.HorizontalResolution > 0 ) && ( sourceImage.VerticalResolution > 0 ) )
                {
                    result.SetResolution( sourceImage.HorizontalResolution, sourceImage.VerticalResolution );
                }
            }
            finally
            {
                sourceImage.UnlockBits( data );
            }

            return result;
        }

Same methods

OrderedColorDithering::Apply ( UnmanagedImage sourceImage ) : Bitmap

Usage Example

Example #1
0
 public static Bitmap OrderedColorDithering(Bitmap bmp, int value)
 {
     // create color image quantization routine
     ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer());
     // create 256 colors table
     Color[] colorTable = ciq.CalculatePalette(bmp, value);
     // create dithering routine
     OrderedColorDithering dithering = new OrderedColorDithering();
     dithering.ColorTable = colorTable;
     // apply the dithering routine
     Bitmap newImage = dithering.Apply(bmp);
     return newImage;
 }