GetNearestColorIndex() публичный Метод

public GetNearestColorIndex ( Color color ) : byte
color Color
Результат byte
Пример #1
0
        private void LoadFromPixelData(byte[] data)
        {
            Title = "Untitled";
            Author = new User("Someone", "Nowhere", new byte[] { 0, 0, 0, 0, 0, 0 });
            Type = PatternType.Normal;

            Color[,] sourceImage = new Color[Width, Height];
            for (int i = 0; i < Width; i++)
                for (int j = 0; j < Height; j++)
                    sourceImage[i, j] = new Color(data[(j * Height + i) * 3 + 2], data[(j * Height + i) * 3 + 1], data[(j * Height + i) * 3 + 0]);

            HashSet<Color> bestPalette = CreateBestPalette(sourceImage);
            ColorPalette = new Palette();
            int k = 0;
            foreach (Color c in bestPalette)
                ColorPalette.SetColor(k++, c);

            for (int i = 0; i < Width; i++)
                for (int j = 0; j < Height; j++)
                    Data[i, j] = ColorPalette.GetNearestColorIndex(sourceImage[i, j]);
        }
Пример #2
0
        private void LoadFromPixelData(byte[] data)
        {
            Color[,] sourceImage = new Color[Width, Height];
            for (int i = 0; i < Width; i++)
                for (int j = 0; j < Height; j++)
                    sourceImage[i, j] = new Color(
                        data[(j * Height + i) * 4 + 2],
                        data[(j * Height + i) * 4 + 1],
                        data[(j * Height + i) * 4 + 0],
                        data[(j * Height + i) * 4 + 3]);

            HashSet<Color> bestPalette = CreateBestPalette(sourceImage);
            ColorPalette = new Palette();
            int k = 0;
            foreach (Color c in bestPalette)
                ColorPalette.SetColor(k++, c);

            for (int i = 0; i < Width; i++)
                for (int j = 0; j < Height; j++)
                    Data[i, j] = ColorPalette.GetNearestColorIndex(sourceImage[i, j]);
        }