您好我在使用以下代码时遇到了一些问题。
我得到要生成的图像,但是一旦我调用删除它就会告诉我tesseract正在使用图像并且无法删除它。
有没有办法可以在调用下载之前关闭图像?
private void timer3_Tick(object sender, EventArgs e)
{
ocrconvert();
File.Delete("C:\\temp\\bm.BMP");\\ get the error here
timer3.Interval = 100;
capturescreen();
}
void capturescreen()
{
int one = Convert.ToInt32(Properties.Settings.Default.imagetopx);
int two = Convert.ToInt32(Properties.Settings.Default.imagetopy);
Bitmap bm = new Bitmap(300, 300);
Graphics gp = Graphics.FromImage(bm as Image);
currentimage = currentimage + 1;
gp.CopyFromScreen(one, two, 0, 0, bm.Size);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
bm.Save("C:\\temp\\bm.BMP");
pictureBox1.Image = bm;
startplaying();
timer3.Stop();
timer3.Start();
}
public void ocrconvert()
{
var img = new Bitmap("C:\\temp\\bm.BMP");
var ocr = new TesseractEngine("./tessdata", "eng",
EngineMode.TesseractAndCube);
var page = ocr.Process(img);
label24.Text = page.GetText();
page.Dispose();
}