///选取图片按钮的代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 选择图片_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "JPG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png";
openFileDialog.FilterIndex = 1;
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
selectedPicture = openFileDialog.FileName;
MessageBox.Show($"您选中的图片路径为:{selectedPicture}");
// 使用Image类加载图片
Image image = Image.FromFile(selectedPicture);
// 将图片显示在PictureBox中
pictureBox1.Image = image;
}
else
{
MessageBox.Show("您本次没有选择任何图片!!!");
}
}
/// <summary>
/// 开始识别按钮的代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 识别_Click(object sender, EventArgs e)
{
//创建扫描器
OcrScanner scanner = new OcrScanner();
//开始扫描
if (selectedPicture!=null)
scanner.Scan(selectedPicture);
//输出结果
string result = scanner.Text.ToString();
richTextBox1.Text = result;
//替换掉最后一句话
string result2 = result.Replace("Evaluation Warning : The version can be used only for evaluation purpose...", "");
richTextBox1.Text = result2;
}
使用Nuget安装Spire.OCR的包
将目标平台设置为X64
要将 \项目名\packages\Spire.OCR.1.8.0\runtimes\win-x64\native内的ddl,复制粘贴到 \项目名\bin\x64\Debug内