private void button1_Click(object sender, EventArgs e) { if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ImageFormat fmt = null; //jpg|*jpg|gif|*.gif|png|*.png|bmp|*.bmp|ico|*.ico switch (saveFileDialog1.FilterIndex) { case 1: fmt = ImageFormat.Jpeg; break; case 2: fmt = ImageFormat.Gif; break; case 3: fmt = ImageFormat.Png; break; case 4: fmt = ImageFormat.Bmp; break; case 5: fmt = ImageFormat.Icon; break; } using (ImageChanged image = new ImageChanged(textBox1.Text)) { image.Save(saveFileDialog1.FileName, fmt); } } }
private void button3_Click(object sender, EventArgs e) { if (!Directory.Exists(lblout.Text)) { Directory.CreateDirectory(lblout.Text); } string[] files = Directory.GetFiles(textBox3.Text); string exf = ""; ImageFormat imgfmt = null; switch (comboBox1.SelectedIndex) { case 0: exf = ".jpg"; imgfmt = ImageFormat.Jpeg; break; case 1: exf = ".gif"; imgfmt = ImageFormat.Gif; break; case 2: exf = ".png"; imgfmt = ImageFormat.Png; break; case 3: exf = ".bmp"; imgfmt = ImageFormat.Bmp; break; } foreach (string f in files) { try { using (ImageChanged image = new ImageChanged(f)) { string filename = Path.GetFileNameWithoutExtension(f); string outfile = Path.Combine(lblout.Text, filename + exf); if (checkBox1.Checked) { image.Resize((int)numericUpDown1.Value, (int)numericUpDown2.Value); } image.Save(outfile, imgfmt); } } catch { } } }