Exemple #1
0
        public ImageItem(string path, string outputPath, int newSize)
        {
            ImageFormat extension;
            string      outputName;

            Filename      = Path.GetFileName(path);
            ThumbnailSize = 20;

            var originalImage = new Bitmap(path);

            extension     = originalImage.RawFormat;
            originalImage = Processing.ChangePixelFormat(originalImage, PixelFormat.Format32bppRgb);

            Bitmap croppedImage = Processing.CropImage(originalImage, newSize);

            outputName = string.Concat(outputPath, "\\", Filename);
            croppedImage.Save(outputName, extension);

            Thumbnail = Processing.CreateThumbnail(croppedImage, ThumbnailSize);

            var AverageColor = Processing.CalculateAvgColor(originalImage);

            AverageHSB = new float[3] {
                AverageColor.GetHue(), AverageColor.GetSaturation(), AverageColor.GetBrightness()
            };

            originalImage.Dispose();
            croppedImage.Dispose();
        }
Exemple #2
0
        public void Process(string originalImagePath, string imagesDBPath, int tiles)
        {
            Img = (Bitmap)Image.FromFile(originalImagePath);
            Img = Processing.ChangePixelFormat(Img, PixelFormat.Format32bppRgb);

            Db = Utilities.DeserializeItem(imagesDBPath + "\\data.bin") as ImagesDatabase;

            OutputImg = CreateMozaic(tiles, imagesDBPath);
        }
Exemple #3
0
        private Bitmap CreateMozaic(int tiles, string imagesDBPath)
        {
            int count        = 0;
            int pixels       = Img.Width / tiles;
            int cols         = tiles;
            int rows         = Img.Height / pixels;
            int mozaicWidth  = cols * Db.ImagesSize;
            int mozaicHeight = rows * Db.ImagesSize;

            byte[,,] mozaic = new byte[mozaicWidth, mozaicHeight, 3];

            int numOfThreads = Environment.ProcessorCount - 2;

            numOfThreads = numOfThreads < 2 ? 2 : numOfThreads;
            var options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = numOfThreads
            };

            Parallel.For(0, rows, options, j =>
            {
                var rng = new Random();
                for (int i = 0; i < cols; i++)
                {
                    Bitmap fragment;
                    lock (_lockResources)
                    {
                        count++;
                        double dprogress = (count / (double)(cols * rows)) * 100.0;
                        ProgressChanged?.Invoke(this, new ProgressChangedEventHandler((int)dprogress));
                        fragment = Img.Clone(new Rectangle(i * pixels, j * pixels, pixels, pixels), PixelFormat.Format32bppRgb);
                    }

                    ImageItem bestImage = FindBest(fragment, rng);
                    var bestImagePath   = Path.Combine(imagesDBPath, bestImage.Filename);
                    Bitmap bestImageBMP = (Bitmap)Image.FromFile(bestImagePath);
                    bestImageBMP        = Processing.ChangePixelFormat(bestImageBMP, PixelFormat.Format32bppRgb);
                    //bestImageBMP = AdjustColor(bestImageBMP, fragment, bestImage);
                    byte[,,] bestImageArr = Processing.BitmapToRGBArray(bestImageBMP);

                    bestImageBMP.Dispose();
                    fragment.Dispose();

                    lock (_lockResources2)
                    {
                        Processing.PasteArray(ref mozaic, bestImageArr, i * Db.ImagesSize, j * Db.ImagesSize);
                    }
                }
            });

            return(Processing.RGBArrayToBitmap(mozaic));
        }