Пример #1
0
        private void btnCollage_Click(object sender, EventArgs e)
        {
            if (imagesList == null || imagesList.Count == 0)
            {
                ShowInformation("No images selected.");
                return;
            }

            ShowInformation("Work in progress...");
            DisableControls();

            var settings =
                new CollageSettings(
                    new CollageDimensionSettings
                        {
                            NumberOfColumns = Convert.ToInt32(nudColumns.Value),
                            NumberOfRows = Convert.ToInt32(nudRows.Value),
                            TileHeight = Convert.ToInt32(nudItemHeight.Value),
                            TileWidth = Convert.ToInt32(nudItemWidth.Value),
                            TileScalePercent = new Percentage(Convert.ToInt32(nudScalePercent.Value))
                        },
                        new AdditionalCollageSettings
                            {
                                RotateAndFlipRandomly = cbRotateAndFlip.Checked,
                                CutTileRandomly = cbCutRandomly.Checked
                            },
                        imagesList,
                        new DirectoryInfo(folderBrowserDialog1.SelectedPath)
                    );

            CreateCollage(settings);
        }
 public void CreateCollage(int columns, int rows)
 {
     DirectoryInfo di = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath("~/Content/Images/"));
     DirectoryInfo diroutput = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath("~/Content/DoneCollage/"));
     {
         List<FileInfo> files = di.GetFiles().ToList();
         var setting = new CollageSettings(
             new CollageDimensionSettings
             {
                 NumberOfColumns = columns,
                 NumberOfRows = rows,
                 TileScalePercent = new Percentage(100),
                 TileHeight = 50,
                 TileWidth = 50
             },
             new AdditionalCollageSettings
             {
                 CutTileRandomly = false,
                 RotateAndFlipRandomly = false
             },
             files, diroutput);
         var collage = new CollageGenerator(setting);
         collage.Create();
         if (File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Content/DoneCollage/") + "result.jpg"))
         {
             foreach (FileInfo file in di.GetFiles())
             {
                 file.Delete();
             }
         }
     }
 }
Пример #3
0
 public CollageGenerator(CollageSettings settings)
 {
     if (settings == null)
     {
         ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), "settings");
     }
     this.settings        = settings;
     this.progressCounter = new ProgressCounter(settings.Dimensions.NumberOfRows, settings.Dimensions.NumberOfColumns);
     this.randomGenerator = new RandomGenerator();
     this.tileTransformer = new TileTransformer();
     this.filesEnumerator = new DateFilesEnumerator(settings.InputFiles);
     this.collageSaver    = new CollageSaver(settings.OutputDirectory);
 }
Пример #4
0
        public CollageGenerator(CollageSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            this.settings = settings;
            this.progressCounter = new ProgressCounter(settings.Dimensions.NumberOfRows, settings.Dimensions.NumberOfColumns);
            this.randomGenerator = new RandomGenerator();
            this.tileTransformer = new TileTransformer();
            this.filesEnumerator = new DateFilesEnumerator(settings.InputFiles);
            this.collageSaver = new CollageSaver(settings.OutputDirectory);
        }
Пример #5
0
        static void Main(string[] args)
        {
            var options = CreateOptions();

            try
            {
                options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("{0}: ", programName);
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help' for more information.", programName);
                return;
            }

            if (showHelp)
            {
                ShowHelp(options);
                return;
            }

            if (!ValidateOptions())
                return;

            var imagesList = new List<FileInfo>();
            imagesList.AddRange(Directory.GetFiles(inputDirectory, "*.jpg").Select(name => new FileInfo(name)));

            if (imagesList.Count == 0)
            {
                var dirInfo = new DirectoryInfo(inputDirectory);
                Console.WriteLine("No images found in {0}.", dirInfo.FullName);
                return;
            }

            Console.WriteLine("Number of images found: {0}", imagesList.Count);

            var collageSettings =
                new CollageSettings(
                    new CollageDimensionSettings
                        {
                            NumberOfColumns = numberOfColums,
                            NumberOfRows = numberOfRows,
                            TileHeight = tileHeight,
                            TileWidth = tileWidth,
                            TileScalePercent = new Percentage(scalePercent)
                        },
                    new AdditionalCollageSettings
                        {
                            RotateAndFlipRandomly = rotateAndFlipRandomly
                        },
                    imagesList,
                    new DirectoryInfo(outputDirectory));

            var collage = new CollageGenerator(collageSettings);

            collage.Create();

            Console.WriteLine("Collage saved");
        }
Пример #6
0
        private void CreateCollage(CollageSettings settings)
        {
            this.collage = new CollageGenerator(settings);

            collage.CreateCompleted += this.collage_CreateCompleted;
            collage.CreateProgressChanged += this.collage_CreateProgressChanged;

            collage.CreateAsync();
        }