Размытие и резкость изображения, с помощью AForge.NET
Категория: .NET
2011-09-07 00:18:15
code: #csharp
- using AForge;
- using AForge.Imaging;
- using AForge.Imaging.Filters;
- using AForge.Imaging.Textures;
- namespace Размытие_и_резкость
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- //Размытие
- private void button1_Click(object sender, EventArgs e)
- {
- pictureBox1.Image = DoF(new Blur());
- }
- //выбор файла
- private void button3_Click(object sender, EventArgs e)
- {
- OpenFileDialog o = new OpenFileDialog();
- o.ShowDialog();
- pictureBox1.Image = System.Drawing.Image.FromFile(o.FileName);
- }
- //резкость
- private void button2_Click(object sender, EventArgs e)
- {
- pictureBox1.Image = DoF(new Sharpen());
- }
- private void button4_Click(object sender, EventArgs e)
- {
- ResizeForm form = new ResizeForm();
- form.OriginalSize = new Size(pictureBox1.Image.Width, pictureBox1.Image.Height);
- if (form.ShowDialog() == DialogResult.OK)
- {
- pictureBox1.Image= DoF(form.Filter);
- }
- }
- private System.Drawing.Image DoF(IFilter f)
- {
- try
- {
- IFilter filter = f;
- // set wait cursor
- this.Cursor = Cursors.WaitCursor;
- Bitmap image = pictureBox1.Image as Bitmap;
- // apply filter to the image
- Bitmap newImage = filter.Apply(image);
- return newImage as System.Drawing.Image;
- }
- catch (ArgumentException)
- {
- MessageBox.Show("Selected filter can not be applied to the image", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return null;
- }
- finally
- {
- // restore cursor
- this.Cursor = Cursors.Default;
- }
- }
- }
- }
Поделиться: