这篇写的内容如题目所示,是跟unity没什么关系的一篇。
公司让我写winform,而我之前只学过MFC,没办法,虽然是赶鸭子上架,但好在还是抱着学习的态度完成了完成了。现在看来这个工程确实不值一提,我只是轮子的使用者,但之于我的意义更多的在于新的比较陌生的东西的学习吧。
在新建一个winform工程时,工程内会自动生成四个脚本:Program.cs;Form1.cs;Form1.cs[Design];Form1.Designer.cs
其中,Program是程序入口;Form1.cs[Design]是我们用来调整窗口布局的
我们可以调出Toolbox来为窗体添加各种控件;并且在我们添加了控件后,在Form1.Designer.cs中会出现控件相应信息;而在Form1中会生成相应的按钮事件。
首先我们在浏览文件夹的触发事件中写:
private void button1_Click(object sender, EventArgs e)
{//浏览文件夹
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
if (this.folderBrowserDialog1.SelectedPath.Trim() != "")
{
this.textBox1.Text = this.folderBrowserDialog1.SelectedPath.Trim();
}
}
}
接着在按钮开始监视中写入;
private void button2_Click(object sender, System.EventArgs e)
{//开始监视文件系统变化情况
if (!System.IO.Directory.Exists(this.textBox1.Text))
{
MessageBox.Show("选择的不是一个文件夹", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
this.fileSystemWatcher1.Path = this.textBox1.Text;
MessageBox.Show(this.textBox1.Text + "已经处于被监视状态!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
这样 this.fileSystemWatcher1.Path就得到了要监控文件夹的路径。这样我们对目标文件夹中的文件进行操作时就会触发相应的创建、更改、删除。重命名的函数。
private void fileSystemWatcher1_Deleted(object sender, System.IO.FileSystemEventArgs e)
{//删除
this.textBox2.Text += "\r\n刚刚删除:" + e.FullPath.ToString();
this.textBox2.Text += "\r\n";
}
private void fileSystemWatcher1_Renamed(object sender, System.IO.RenamedEventArgs e)
{//更名
this.textBox2.Text += "\r\n刚刚更名:" + e.FullPath.ToString();
this.textBox2.Text += "\r\n";
}
private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
{//发生改变s
//this.textBox2.Text += e.FullPath.ToString() + " 发生改变!\n";
}
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{//新增
this.textBox2.Text += "\r\n刚刚新增:" + e.FullPath.ToString()+"\r\n";
Console.WriteLine("ADD");
Console.WriteLine("Fulle");
Console.WriteLine(e.FullPath);
//Init();
//InitOCR(e.FullPath.ToString());
InitOcr("", "eng", OcrEngineMode.TesseractCubeCombined,e);
}
这里讲接下来的OCR入口放在新图片创建的触发事件中。
接下来的一段代码是包括新图片的旋转存储,字母区域的截取和识别,并将旋转后图片的路径和识别结果写入一个text文件。
之前写EMGU差不多交代了,就不多写了先。