Example #1
0
        private static void ShrinkAll()
        {
            List <string> Files = FileClass.GetAllFileNames(MainPicFolder);

            foreach (string File in Files)
            {
                FileClass.CreateThumbnail(15, 30, File);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Bitmap InputFile = new Bitmap(InputFilePath);

            ShrinkAll();
            List <string> AllShrunkFiles             = FileClass.GetAllFileNames(ShrunkenImages);
            List <ClassClass.ShrunkImages> ImageList = new List <ClassClass.ShrunkImages>();
            List <ClassClass.BlockAddress> Blocks    = new List <ClassClass.BlockAddress>();

            ImageAverages(AllShrunkFiles, ImageList);

            sizeSmallX = ImageList[0].image.Width;
            sizeSmallY = ImageList[0].image.Height;

            Bitmap OutPutFile = new Bitmap(InputFile.Width + sizeSmallX, InputFile.Height + sizeSmallY);

            for (int x = 0; x < InputFile.Width; x = x + sizeSmallX)
            {
                for (int y = 0; y < InputFile.Height; y = y + sizeSmallY)
                {
                    ClassClass.BlockAddress Temp = new ClassClass.BlockAddress();
                    Temp.startX = x;
                    Temp.endX   = x + sizeSmallX;
                    Temp.startY = y;
                    Temp.endY   = y + sizeSmallY;
                    Blocks.Add(Temp);
                }
            }

            foreach (ClassClass.BlockAddress BA in Blocks)
            {
                Console.WriteLine("xStart: " + BA.startX + " xEnd: " + BA.endX + " yStart: " + BA.startY + " yEnd: " + BA.endY);
            }
            Console.WriteLine(string.Format("Size: {0} {1} BLOCKS {2}", InputFile.Width, InputFile.Height, Blocks.Count));
            //Console.ReadKey();

            foreach (ClassClass.BlockAddress BA in Blocks)
            {
                if (BA.endX < InputFile.Width && BA.endY < InputFile.Height)
                {
                    float BlockScore = 0;
                    float r = 0, g = 0, b = 0, a = 0;

                    for (int x = BA.startX; x < BA.endX; x++)
                    {
                        for (int y = BA.startY; y < BA.endY; y++)
                        {
                            Color pixel = InputFile.GetPixel(x, y);
                            r = r + pixel.R;
                            g = g + pixel.G;
                            b = b + pixel.B;
                            a = a + pixel.A;
                        }
                    }
                    //BlockScore = r + g + b;
                    BlockScore = GetScore(r, g, b);
                    ClassClass.ShrunkImages Chosen = ChooseImage(ImageList, BlockScore);

                    int xj = 0;
                    int yj = 0;
                    for (int x = BA.startX; x <= BA.endX; x++)
                    {
                        if (xj == sizeSmallX)
                        {
                            xj = 0;
                        }
                        for (int y = BA.startY; y <= BA.endY - 1; y++)
                        {
                            if (yj == sizeSmallY)
                            {
                                yj = 0;
                            }
                            Color pixel = Chosen.image.GetPixel(xj, yj);
                            // Color pixel = Chosen.image.GetPixel(1, 99);
                            // Console.WriteLine(Chosen.image.Width + " " + Chosen.image.Height);
                            OutPutFile.SetPixel(x, y, pixel);
                            yj++;
                        }
                        xj++;
                    }
                }
            }
            //Console.ReadKey();

            int DeltaX = InputFile.Width / sizeSmallX;
            int DeltaY = InputFile.Height / sizeSmallY;


            /*for(int x = 0; x < InputFile.Width; x = x + sizeSmallX)
             * {
             *  for(int y = 0; y < InputFile.Height; y = y + sizeSmallY)
             *  {
             *      float BlockScore = 0;
             *      float r = 0;
             *      float g = 0;
             *      float b = 0;
             *      BlockData(InputFile, sizeSmallX, sizeSmallY, x, y, ref r, ref g, ref b);
             *      BlockScore = (r + g + b) / 3;
             *      ClassClass.ShrunkImages ChosenImage = new ClassClass.ShrunkImages();
             *      ChosenImage = ChooseImage(ImageList, BlockScore, ChosenImage);
             *      int Thumbx = 0;
             *      int Thumby = 0;
             *      while(Thumbx < sizeSmallX)
             *      {
             *           while(Thumby < sizeSmallY)
             *          {
             *              Color pixel = ChosenImage.image.GetPixel(Thumbx, Thumby);
             *              OutPutFile.SetPixel(x + Thumbx, y + Thumby, pixel);
             *              //OutPutFile.Save(".\\output.png");
             *              Thumby++;
             *          }
             *          Thumbx++;
             *      }
             *
             *
             *
             *  }
             * }*/

            OutPutFile.Save(".\\output.png");
        }