Exemple #1
0
        //default 8-pallete
        public static Bitmap BurkesColorDithering(Bitmap sourceImage, int paletteSize)
        {
            ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer());

            Color[] colorTable          = ciq.CalculatePalette(sourceImage, paletteSize);
            BurkesColorDithering filter = new BurkesColorDithering();

            filter.ColorTable = colorTable;
            return(filter.Apply(sourceImage));
        }
        public static Bitmap BurkesColorDithering(Bitmap bmp, int value)
        {
            // create color image quantization routine
            ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer());

            // create 8 colors table
            Color[] colorTable = ciq.CalculatePalette(bmp, value);
            // create dithering routine
            BurkesColorDithering dithering = new BurkesColorDithering();

            dithering.ColorTable = colorTable;
            // apply the dithering routine
            Bitmap newImage = dithering.Apply(bmp);

            return(newImage);
        }
        public Bitmap Convert(Bitmap source, Size size)
        {
            if (source == null)
            {
                return(null);
            }

            Bitmap result = source.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            if (result.Size != size)
            {
                if (size.Width >= result.Width && size.Height >= result.Height)
                {
                    size = result.Size; // no change
                }
                else
                {
                    var ratioWidth  = (double)size.Width / result.Width;
                    var ratioHeight = (double)size.Height / result.Height;

                    var ratio = Math.Min(ratioWidth, ratioHeight);
                    size = new Size((int)(result.Width * ratio), (int)(result.Height * ratio));

                    ResizeBicubic filter = new ResizeBicubic(size.Width, size.Height);
                    result = filter.Apply(result);
                }
            }

            ColorImageQuantizer  colorImageQuantizer = new ColorImageQuantizer(new MedianCutQuantizer());
            BurkesColorDithering dither = new BurkesColorDithering
            {
                ColorTable = palette
            };

            result = dither.Apply(result);

            return(result);
        }