图像处理控件ImageGear for .NET课程:C# WPF应用程序创建示例(2)
图像处理控件ImageGear for .NET教程:C# WPF应用程序创建示例(2)
在前面的《图像处理控件ImageGear for .NET教程: C# WPF应用程序创建示例(1)》一文中已经讲解了如何在ImageGear for .NET 中对于C# WPF应用程序创建了项目,本文将继续前文。
设计窗体
一、创建在窗体中的菜单
- 在Windows Forms工具箱中,拖一个MenuStrip控件到这个窗体中。
- 创建三个菜单,命名为File、View、Processing。
- 在File菜单下,添加Load Page 和 Exit。
- 在View菜单下,添加Zoom In 和 Zoom Out。
- 在Processing菜单下,添加Rotate 90、Rotate 180、Rotate 270。
- 对于本次的教程,保持控件默认的名称,并双击每个项目,创建一个控制器。
二、在窗体中添加ImageGear Page View控件
- 在Windows Forms工具箱中,拖拽ImGearPageView控件到窗体上。
- 设置imGearPageView1控件的Dock属性为“fill”,这个将会使得控件以窗体来重新调整。
- 保留默认的控件名称,比如imGearPageView1控件。现在窗体的外观就会如下所示:
开发应用程序
一、首先,添加必要的using语句
- 通过右键单击窗口打开窗口代码,选择查看代码。
- 在代码的最上面,添加下面的语句。
using System.IO; using System.Diagnostics; using ImageGear; using ImageGear.Core; using ImageGear.Windows.Forms; using ImageGear.Display; using ImageGear.Processing; using ImageGear.Formats;
二、添加下面的域到Form1:
// holds the image data private ImGearPage imGearPage = null; // controls how the page is displayed private ImGearPageDisplay imGearPageDisplay = null;
三、如果你使用的是运行时授权,调用InitializeComponent之前,添加授权初始化代码到Form1构造函数(Form1())。如果你使用的是评估或开发(工具包)授权的话,就不需要。
//***The SetSolutionName, SetSolutionKey and possibly the SetOEMLicenseKey //methods must be called to distribute the runtime.*** //ImGearLicense.SetSolutionName("YourSolutionName"); //ImGearLicense.SetSolutionKey(12345, 12345, 12345, 12345); //Manually Reported Runtime licenses also require the following method //call to SetOEMLicenseKey. //ImGearLicense.SetOEMLicenseKey("2.0.AStringForOEMLicensing...");
四、在之前代码的下面,添加下面的调用来初始化引用的格式。
// Support for common formats:
五、现在在导入页面菜单控制器中添加下面的代码:
private void loadPageToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = ImGearFileFormats.GetSavingFilter(ImGearSavingFormats.UNKNOWN); if (DialogResult.OK == openFileDialog1.ShowDialog()) { using (FileStream stream = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { try { // Load the image into the page imGearPage = ImGearFileFormats.LoadPage(stream, 0); } catch (ImGearException ex) { Debug.WriteLine(ex.Message); } } if (null != imGearPage && null != imGearPage.DIB && !imGearPage.DIB.IsEmpty()) { // create a new page display imGearPageDisplay = new ImGearPageDisplay(imGearPage); // associate the page display with the page view imGearPageView1.Display = imGearPageDisplay; // cause the page view to repaint imGearPageView1.Invalidate(); } } }
开发应用程序的其他步骤以后再补上哈~~就到这里先