Ejemplo n.º 1
0
            /// <summary>
            ///     Use the median cut algorithm to cluster similar colors.
            /// </summary>
            /// <param name="sourceImage">The source image.</param>
            /// <param name="colorCount">The color count.</param>
            /// <param name="quality">
            ///     0 is the highest quality settings. 10 is the default. There is
            ///     a trade-off between quality and speed. The bigger the number,
            ///     the faster a color will be returned but the greater the
            ///     likelihood that it will not be the visually most dominant color.
            /// </param>
            /// <param name="ignoreWhite">if set to <c>true</c> [ignore white].</param>
            /// <returns></returns>
            public static MMCQ.CMap GetColorMap(
                WriteableBitmap sourceImage,
                int colorCount,
                int quality,
                bool ignoreWhite)
            {
                var pixelArray = GetPixelsFast(sourceImage, quality, ignoreWhite);

                // Send array to quantize function which clusters values using median
                // cut algorithm
                var cmap = MMCQ.Quantize(pixelArray, colorCount);

                return(cmap);
            }
Ejemplo n.º 2
0
        List <ColorBox> GetColorMap(int sx, int sy, int width, int height, int maxColors)
        {
            var pixels = new Color[width * height];

            for (int j = 0; j < height; j++)
            {
                for (int i = 0; i < width; i++)
                {
                    pixels[j * width + i] = _bitmap.GetPixel(sx + i, sy + j);
                }
            }

            var colors = MMCQ.Quantize(pixels, maxColors).ToList();

            colors.Sort((a, b) => b.GetCount().CompareTo(a.GetCount()));

            return(colors);
        }