开发者

Why MODI doesn't let me delete the processed file?

开发者 https://www.devze.com 2023-02-02 10:35 出处:网络
private void button4_Click(object sender, EventArgs e) { OCR.recognize(\"tes开发者_如何学JAVAt1.tif\");
private void button4_Click(object sender, EventArgs e)
{
        OCR.recognize("tes开发者_如何学JAVAt1.tif");
        System.IO.File.Delete("test1.tif"); // <--- Problem on this line
}

....

public static string recognize(string filepath, MODI.MiLANGUAGES language =
MODI.MiLANGUAGES.miLANG_RUSSIAN)
{
        if (!File.Exists(filepath)) return "error 1: File does not exist";
        MODI.Document doc = new MODI.Document();
        doc.Create(filepath);

        doc.OCR(language, true, true);
        MODI.Image image = (MODI.Image)doc.Images[0];

        string result="";
        foreach (MODI.Word worditems in image.Layout.Words)
        {
            result += worditems.Text + ' ';

        // Processed image is ALWAYS a question
            if (worditems.Text[worditems.Text.Length - 1] == '?') break;
        }


        doc.Close();

        return result;

}

Problem is: File is used by another process.

How do I delete it after OCR?


Someone posted a solution for this:

public void Dispose()  
{   
        doc.Close(false); 
        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(doc);
        doc = null; 
        GC.Collect();
}

Maybe it works for your case, too.

0

精彩评论

暂无评论...
验证码 换一张
取 消