/// <summary> /// Creates a list of PixelMatrix objects in the given size from a source image. /// </summary> /// <param name="source">The source image.</param> /// <param name="tileSize">The size of each resulting PixelMatrix.</param> /// <returns>a list of PixelMatrix objects representing the source image.</returns> public static List <PixelMatrix> CreateTiles(BitmapSource source, Size tileSize) { List <PixelMatrix> tiles = new List <PixelMatrix>(); var pixels = source.GetImagePixels(); int rows = source.PixelHeight / tileSize.Height; int cols = source.PixelWidth / tileSize.Width; for (int y = 0; y < rows; y++) { for (int x = 0; x < cols; x++) { tiles.Add(new PixelMatrix(pixels, tileSize, new Point(x * tileSize.Width, y * tileSize.Height), source.PixelWidth * Utils.BytesPerPixel)); } } return(tiles); }