Exemplo n.º 1
0
 public Image QuantizeImage(Bitmap image, int alphaThreshold, int alphaFader, int maxColorCount)
 {
     MaxColor = maxColorCount;
     int colorCount = maxColorCount;
     ColorData moments = QuantizerBase.CalculateMoments(QuantizerBase.BuildHistogram(image, alphaThreshold, alphaFader));
     IEnumerable<Box> cubes = this.SplitData(ref colorCount, moments);
     QuantizedPalette quantizedPalette = this.GetQuantizedPalette(colorCount, moments, cubes, alphaThreshold);
     return (Image)QuantizerBase.ProcessImagePixels((Image)image, quantizedPalette);
 }
Exemplo n.º 2
0
        public Bitmap QuantizeImage(Bitmap image, int alphaThreshold, int alphaFader, int maxColorCount)
        {
            if (image.PixelFormat != PixelFormat.Format32bppArgb)
            {
                image = image.ConvertToFormat32();
            }

            if (Program.DisableQuantization())
            {
                Console.WriteLine("[WARNING] By disabling quantization, only the first 255 unique colors will be taken into account");
                return(image);
            }

            mMaxColor = maxColorCount + 1;
            mMaxColor = Math.Min(mMaxColor, 256);
            int               colorCount       = mMaxColor;
            ColorData         moments          = QuantizerBase.CalculateMoments(QuantizerBase.BuildHistogram(image, alphaThreshold, alphaFader));
            IEnumerable <Box> cubes            = this.SplitData(ref colorCount, moments);
            QuantizedPalette  quantizedPalette = this.GetQuantizedPalette(colorCount, moments, cubes, alphaThreshold);

            return(ProcessImagePixels((Image)image, quantizedPalette));
        }