This code captures an defined area from screen and transfers it into text.
But, i have 2 problems here.
1st. - I cant delete temp file ( File.Delete(strFileName) - it says - the file is used by another process.
2nd. - If i capture an area, where isnt any symbol, it shoots out error - OCR running error.

anybody can help me here ?
//using MODI; (microsoft office document imaging)

int width = 200;
int height = 200;
            Bitmap screen1 = new Bitmap(width, height);
            Graphics screen1G = Graphics.FromImage(screen1);
            screen1G.CopyFromScreen(1, 1, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
            pictureBox1.Image = card1;

            // Create a temp file name.
            string strFileName = "temp" + DateTime.Now.Millisecond +

            // Save the bitmap object to a tiff file.
            screen1.Save(strFileName, System.Drawing.Imaging.ImageFormat.Tiff);

            // Instantiate the MODI.Document object
            MODI.Document md = new MODI.Document();
            // The Create method grabs the picture from
            //   disk snd prepares for OCR.
            // Do the OCR.
            md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);

            // This string will contain the text.
            string strText = String.Empty;

            // Get the first (and only image)
            MODI.Image image = (MODI.Image)md.Images[0];
            // Get the layout.
            MODI.Layout layout = image.Layout;

            // Loop through the words.
            for (int j = 0; j < layout.Words.Count; j++)
                // Get this word.
                MODI.Word word = (MODI.Word)layout.Words[j];
                // Add a blank space to separate words.
                if (strText.Length > 0)
                    strText += " ";
                // Add the word.
                strText += word.Text;
            // Close the MODI.Document object.

            //textBox1.Text = strText;


I have no experience with MODI but it looks like you still have references to the image and layout at the point where you try to delete the image from disk. This might be what is preventing the delete working. (It might also be related to the other error, but that is just a guess).

This article has been dead for over six months. Start a new discussion instead.