コード例 #1
0
ファイル: Form1.cs プロジェクト: SystematixIndore/ImageResize
        private void fileWatcher_Created(object sender, System.IO.FileSystemEventArgs e)
        {
            lblImageAdded.Text += e.ChangeType + ": " + e.FullPath + "\r\n";
            Image  simage    = Image.FromFile(e.FullPath.ToString());
            var    imgStream = ImageResizeAspect.ResizeImage(simage, new Size(200, 200));
            Bitmap omg       = new Bitmap(imgStream);

            string dir   = Path.GetDirectoryName(e.FullPath);
            string fname = Path.GetFileName(e.FullPath);

            dir = dir + "\\Resized";
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            omg.Save(dir + "\\" + fname, System.Drawing.Imaging.ImageFormat.Gif);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: SystematixIndore/ImageResize
        private void btnResize_Click(object sender, EventArgs e)
        {
            var files  = Directory.GetFiles(lblPath.Text, "*.*").ToList();
            var images = files.Where(file => file.ToLower().EndsWith(".jpg") || file.ToLower().EndsWith(".png") || file.ToLower().EndsWith(".gif")).ToList();

            foreach (var pic in images)
            {
                Image  simage    = Image.FromFile(pic.ToString());
                var    imgStream = ImageResizeAspect.ResizeImage(simage, new Size(200, 200));
                Bitmap omg       = new Bitmap(imgStream);

                string dir   = Path.GetDirectoryName(pic);
                string fname = Path.GetFileName(pic);
                dir = dir + "\\Resized";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                omg.Save(dir + "\\" + fname, System.Drawing.Imaging.ImageFormat.Gif);
            }
        }