- 使用 RotateBicubic() 讓圖片旋轉 30 度角。
- 加入 Stopwatch() 顯示圖片處理所花的時間。
Step1. 檔案 → 新增專案 → Windows Form 應用程式 → 拉物件 Form1.cs[設計] → 撰寫 Form1.cs
Step2. 方案總管 → 參考 → 右鍵加入參考 → 瀏灠(預設路徑) C:\Program Files (x86)\AForge.NET\Framework\Release → 加入參考:
- AForge.Imaging.dll
- AForge.Imaging.Formats.dll
Step3. 使用測試圖片:
Step4. Windows Form 拉入需要工具:
- pictureBox × 2
- button × 2
- textBox × 1
- openFileDialog × 1
Step5. Coding
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AForge.Imaging;
using AForge.Imaging.Formats;
using AForge.Imaging.Filters;
using System.Diagnostics;
namespace rotateDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Bitmap imgone;
Stopwatch stopWatch = new Stopwatch();
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "所有檔案(*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
imgone = ImageDecoder.DecodeFromFile(openFileDialog1.FileName);
pictureBox1.Image = imgone;
}
}
private void button2_Click(object sender, EventArgs e)
{
stopWatch.Reset();
stopWatch.Start();
RotateBicubic filter = new RotateBicubic(30, true);
Bitmap rotateImg = filter.Apply(imgone);
pictureBox2.Image = rotateImg;
stopWatch.Stop();
TimeSpan ti = new TimeSpan();
textBox1.Text = ti.ToString();
}
}
}

沒有留言:
張貼留言