public Bitmap pixelCensorship(Image image, int[] coordinates)
        {
            Bitmap bitmap = image.BitmapImage;

            double[] coordinatesDouble = new double[coordinates.Length];
            for (int i = 0; i < coordinates.Length; i++)
            {
                coordinatesDouble[i] = Convert.ToDouble(coordinates[i]);
            }
            Scissors scissors      = new Scissors();
            Resizer  resizer       = new Resizer();
            AddImage AI            = new AddImage();
            Bitmap   cropped       = scissors.Crop(bitmap, coordinatesDouble);
            Bitmap   ResizedSmall  = resizer.ResizeImage(cropped, 10, 10);
            Bitmap   ResizedNormal = resizer.ResizeImage(ResizedSmall, cropped.Width, cropped.Height);
            Bitmap   Final         = AI.InsertImage(bitmap, ResizedNormal, coordinates[0], coordinates[1], coordinates[2], coordinates[3]);

            return(Final);
        }
Exemple #2
0
        public Bitmap ImageCollage(List <Image> images, int widthImage = 1000, int heightImage = 1000,
                                   int widthInsertImage = 100, int heightInsertImage           = 100, Bitmap backgroundImage = null, int R = 0, int G = 0, int B = 0)
        {
            Random  rnd     = new Random();
            Resizer resizer = new Resizer();
            Bitmap  Collage = new Bitmap(widthImage, heightImage);

            if (backgroundImage != null)
            {
                backgroundImage = resizer.ResizeImage(backgroundImage, widthImage, heightImage);
                Collage         = backgroundImage;
            }
            else
            {
                for (int x = 0; x < Collage.Width; x++)
                {
                    for (int y = 0; y < Collage.Height; y++)
                    {
                        Collage.SetPixel(x, y, Color.FromArgb(R, G, B));
                    }
                }
            }
            List <int[]> positions = new List <int[]>();
            int          position  = 0;

            for (int i = 0; i < images.Count; i++)
            {
                int[] coordRandom = { rnd.Next(0, widthImage - widthInsertImage), rnd.Next(0, heightImage - heightInsertImage) };
                positions.Add(coordRandom);
            }
            foreach (Image image in images)
            {
                Collage = InsertImage(Collage, resizer.ResizeImage(image.BitmapImage, widthInsertImage, heightInsertImage),
                                      positions[position][0], positions[position][1], widthInsertImage, heightInsertImage);
                position++;
            }
            return(Collage);
        }
Exemple #3
0
        public System.Drawing.Bitmap Merge(List <Image> images)
        {
            Resizer       resizer = new Resizer();
            List <Bitmap> Final   = new List <Bitmap>();
            int           x       = 0;
            int           y       = 0;

            for (int i = 0; i < images.Count; i++)
            {
                if ((x >= images[i].Resolution[0] && y >= images[i].Resolution[1]) || (x == 0 && y == 0))
                {
                    x = images[i].Resolution[0];
                    y = images[i].Resolution[1];
                }
            }
            foreach (Image image in images)
            {
                Bitmap bitmap = resizer.ResizeImage(image.BitmapImage, x, y);
                Final.Add(bitmap);
            }

            return(MergeRecursive(Final, Final[0], 2));
        }
Exemple #4
0
        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();
            }
        }