public Bitmap Mosaic(Image image, List <Image> images, int width = 10, int height = 10) { Console.WriteLine("Loading images, please wait"); //Converting loaded image into bitmap Resizer resizer = new Resizer(); Bitmap imageBit = image.BitmapImage; Bitmap bmp = (Bitmap)imageBit.Clone(); Scissors scissors = new Scissors(); bmp = resizer.ResizeImage(bmp, 80 * width, 80 * height); int bmpWidth = bmp.Width / (bmp.Width / width); int bmpHeight = bmp.Height / (bmp.Height / height); Console.WriteLine("Dividing Image"); List <int[]> coords = new List <int[]>(); Dictionary <Bitmap, int[]> dict = new Dictionary <Bitmap, int[]>(); for (int i = 0; i < (bmp.Width / width); i++) { for (int y = 0; y < (bmp.Height / height); y++) { Graphics gr = Graphics.FromImage(bmp); Rectangle r = new Rectangle(i * bmpWidth, y * bmpHeight, bmpWidth, bmpHeight); double[] coord = { r.X, r.Y, r.Width, r.Height }; int[] bitCoord = { (i * bmpWidth), (y * bmpHeight), (bmpWidth), (bmpHeight) }; dict.Add(scissors.Crop(bmp, coord), bitCoord); coords.Add(bitCoord); } } List <Bitmap> list = new List <Bitmap>(); foreach (KeyValuePair <Bitmap, int[]> keys in dict) { list.Add(keys.Key); } Console.WriteLine("Getting Avg RGBS"); List <int[]> rgbAVG = avgRGB(list); List <Bitmap> imagesList = new List <Bitmap>(); foreach (Image imageInsert in images) { imagesList.Add(imageInsert.BitmapImage); } Bitmap baseImage = new Bitmap(bmp.Width, bmp.Height); int AvgCont = 0; int max = list.Count; ColorFilter CF = new ColorFilter(); while (true) { double porcentage = ((double)AvgCont / (double)max); BarraCarga("Creando Mosaico", porcentage); if (AvgCont < max) { Color color = Color.FromArgb(rgbAVG[AvgCont][0], rgbAVG[AvgCont][1], rgbAVG[AvgCont][2]); baseImage = InsertImage(baseImage, CF.ApplyFilter(Random(images), color) , coords[AvgCont][0], coords[AvgCont][1], coords[AvgCont][2], coords[AvgCont][3]); } else { return(baseImage); } AvgCont++; GC.Collect(); } }