Beispiel #1
0
        public static Color[] GetColors(this BitmapSource image)
        {
            FormatConvertedBitmap formatConvertedBitmap = new FormatConvertedBitmap(image, PixelFormats.Bgra32, null, 0);
            var data = formatConvertedBitmap.GetData();

            Color[] returned = new Color[data.Length / 4];

            for (int i = 0, k = 0; i < data.Length & k < returned.Length; i += 4, k++)
            {
                returned[k] = Color.FromArgb(
                    data[i + 3],
                    data[i + 2],
                    data[i + 1],
                    data[i]);
            }


            return(returned);
        }