Example #1
0
        private async void buttonMakeTiles_Click(object sender, EventArgs e)
        {
            string title           = this.Text;
            var    progressHandler = new Progress <int>(value =>
            {
                progressBarMakeMozaic.Value = value;
                if (this.Text != value + "%")
                {
                    this.Text = value + "%";
                    this.Refresh();
                }
            });
            var progress = progressHandler as IProgress <int>;

            await Task.Run(() =>
            {
                this.thumbMaker = new ThumbMaker(Properties.Settings.Default.LastPath, Path.Combine(Properties.Settings.Default.appData, "tiles"));
                this.thumbMaker.Process(progress);
            });

            progressBarMakeMozaic.Value = 0;
            this.Text = title;
            this.Refresh();
        }
Example #2
0
        public void Process(IProgress <int> progress)
        {
            //for (int i = 0; i < this.images.Length; i++)
            int   count      = 0;
            var   lockTarget = new object();
            float total      = this.images.Length;

            Parallel.ForEach(this.images, new ParallelOptions {
                MaxDegreeOfParallelism = 4
            }, imagePath =>
            {
                lock (lockTarget)
                {
                    count++;
                }

                int percent = (int)((count / total) * 100f);
                progress.Report(percent);
                string dir = Path.GetDirectoryName(imagePath);// this.images[i]);
                dir        = dir.Replace(this._pathToImages, this.tilesDir);
                int num    = 1;
                lock (lockTarget)
                {
                    if (!folderCount.ContainsKey(dir))
                    {
                        folderCount.Add(dir, 1);
                    }
                    else
                    {
                        folderCount[dir] += 1;
                        num = folderCount[dir];
                    }
                }
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                string fname = Path.Combine(dir, num.ToString());// Path.GetFileNameWithoutExtension(imagePath));//this.images[i]));
                if (File.Exists(fname + ".jpg"))
                {
                    return;                             // continue;
                }
                Bitmap tmpbmp = new Bitmap(this.thumbSize, this.thumbSize);

                using (Image im = Image.FromFile(imagePath))//this.images[i]))
                {
                    // First resize
                    Bitmap imS = new Bitmap(3 * this.thumbSize, 3 * this.thumbSize);
                    ThumbMaker.ResizeImage(ref imS, im, 3 * this.thumbSize);
                    Bitmap tmpfull = new Bitmap(imS.Width, imS.Height);

                    //using (Bitmap res = ThumbMaker.ResizeImage(ref tmpbmp, im, this.thumbSize))
                    ThumbMaker.ResizeImage(ref tmpbmp, imS, this.thumbSize);
                    string p = fname + "0.jpg";
                    tmpbmp.Save(p, ImageFormat.Jpeg);

                    // 45 degrees
                    ThumbMaker.RotateImage(ref tmpfull, imS, 45, 1.4f);
                    ThumbMaker.ResizeImage(ref tmpbmp, tmpfull, this.thumbSize);
                    tmpbmp.Save(fname + "1" + ".jpg", ImageFormat.Jpeg);

                    // -45
                    ThumbMaker.RotateImage(ref tmpfull, imS, -45, 1.4f);
                    ThumbMaker.ResizeImage(ref tmpbmp, tmpfull, this.thumbSize);
                    tmpbmp.Save(fname + "2" + ".jpg", ImageFormat.Jpeg);

                    // +22
                    ThumbMaker.RotateImage(ref tmpfull, imS, 22, 1.3f);
                    ThumbMaker.ResizeImage(ref tmpbmp, tmpfull, this.thumbSize);
                    tmpbmp.Save(fname + "3" + ".jpg", ImageFormat.Jpeg);

                    //-22
                    ThumbMaker.RotateImage(ref tmpfull, imS, -22, 1.3f);
                    ThumbMaker.ResizeImage(ref tmpbmp, tmpfull, this.thumbSize);
                    tmpbmp.Save(fname + "4" + ".jpg", ImageFormat.Jpeg);

                    /*Image minus45 = ThumbMaker.RotateImage(res, -45, 1.4f);
                     * minus45.Save(fname + "_-45" + ".jpg", ImageFormat.Jpeg);
                     * minus45.Dispose();
                     *
                     * Image plus22 = ThumbMaker.RotateImage(res, 22, 1.3f);
                     * plus22.Save(fname + "_22" + ".jpg", ImageFormat.Jpeg);
                     * plus22.Dispose();
                     *
                     * Image minus22 = ThumbMaker.RotateImage(res, -22, 1.3f);
                     * minus22.Save(fname + "_-22" + ".jpg", ImageFormat.Jpeg);
                     * minus22.Dispose();*/

                    //res.Dispose();

                    im.Dispose();
                    tmpfull.Dispose();
                }
                tmpbmp.Dispose();
            });
        }