1

在调试时我得到了这样的错误尝试读取或写入受保护的内存。这通常表明其他内存已损坏。

下面的错误代码行适用于捕获屏幕并执行 ocr。但是动态地(意味着具有特定时间限制的多个时间捕获窗口)更改窗口捕获并执行 ocr 会给出错误。

private void OCRImplementationall()
        {
            MODI.Document md = new MODI.Document();

            Cursor = Cursors.WaitCursor;
            string Name = AppDomain.CurrentDomain.BaseDirectory + @"PT INFO.JPG";
            try
            {
                int fflag = 0;
                CheckForIllegalCrossThreadCalls = false;
                md.Create(Name);
                md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
                string strText = String.Empty;

                MODI.Image image = (MODI.Image)md.Images[0];
                MODI.Layout layout = image.Layout;
                string[] splvalues = layout.Text.Trim().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                //for (int i = 0; i < layout.Words.Count; i++)
                int i = 0;
                foreach (string val in splvalues)
                {}}
  catch (Exception ex)
            {
               //ExceptionHelper exlne = new ExceptionHelper();

                LogFile(ex.Message, "OCRImplementationall", "PT INFO Image Error", ExceptionHelper.LineNumber(ex), this.FindForm().Name);


                //MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
}

//捕获并做ocr的函数

 public void screenCaptureDOB(bool showCursor)
        {
            try
            {
                Point curPos = new Point(843, 231);

                //Point curPos = new Point(Cursor.Position.X - CurrentTopLeft.X, Cursor.Position.Y - CurrentTopLeft.Y);
                Size curSize = new Size();
                try
                {
                    curSize.Height = Cursor.Current.Size.Height;
                    curSize.Width = Cursor.Current.Size.Width;

                    ScreenPath = AppDomain.CurrentDomain.BaseDirectory + @"DOB.JPG";
                    if (System.IO.File.Exists(ScreenPath))
                    {
                        System.IO.File.Delete(ScreenPath);
                    }
                    //if (!ScreenShot.saveToClipboard)
                    //{

                    //    saveFileDialog1.DefaultExt = "bmp";
                    //    saveFileDialog1.Filter = "bmp files (*.bmp)|*.bmp|jpg files (*.jpg)|*.jpg|gif files (*.gif)|*.gif|tiff files (*.tiff)|*.tiff|png files (*.png)|*.png";
                    //    saveFileDialog1.Title = "Save screenshot to...";
                    //    saveFileDialog1.ShowDialog();
                    //    ScreenPath = saveFileDialog1.FileName;

                    //}

                }
                catch (Exception ex)
                {
                    LogFile(ex.Message, "screenCaptureDOB", "DOB IMAGE ERROR", ExceptionHelper.LineNumber(ex), this.FindForm().Name);

                                       }
                if (ScreenPath != "" || ScreenShot.saveToClipboard)
                {

                    System.Threading.Thread.Sleep(250);
                    //Allow 250 milliseconds for the screen to repaint itself (we don't want to include this form in the capture)
                    Point StartPoint = new Point(80, 194);
                    Rectangle bounds = new Rectangle(80, 194, 1043, 59);

                    //Point StartPoint = new Point(CurrentTopLeft.X, CurrentTopLeft.Y);
                    //Rectangle bounds = new Rectangle(CurrentTopLeft.X, CurrentTopLeft.Y, CurrentBottomRight.X - CurrentTopLeft.X, CurrentBottomRight.Y - CurrentTopLeft.Y);
                    string fi = "";

                    if (ScreenPath != "")
                    {

                        fi = new System.IO.FileInfo(ScreenPath).Extension;

                    }
                    this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
                    this.TopMost = false;
                    // ScreenShot.CaptureImage(showCursor, curSize, curPos, StartPoint, Point.Empty, bounds, ScreenPath, fi);
                    ScreenShot.CaptureImage(showCursor, curSize, curPos, StartPoint, Point.Empty, bounds, ScreenPath, fi);



                    //The screen has been captured and saved to a file so bring this form back into the foreground
                    OCRImplementationDOB();
                    //OCRImplementationall();

                    //if (ScreenShot.saveToClipboard)
                    //{
                    //    LogFile("Screen saved to clipboard", "screenCaptureDOB", "DOB IMAGE", 1, this.FindForm().Name);

                                           //}
                    //else
                    //{
                    //    LogFile("Screen saved to file", "screenCaptureDOB", "DOB IMAGE ERROR", 1, this.FindForm().Name);


                    //}


                }
            }
            catch (Exception EXC)
            {
                LogFile(EXC.Message, "screenCaptureDOB", "DOB IMAGE ERROR", ExceptionHelper.LineNumber(EXC), this.FindForm().Name);

            }



        }

程序集:“Interop.MODI”,版本=12.0.0.0

System.Runtime.InteropServices.COMException:{“服务器抛出异常。(来自 HRESULT 的异常:0x80010105(RPC_E_SERVERFAULT))”}

来源:“Interop.MODI”

堆栈跟踪:

" 在 MODI.DocumentClass.OCR(MiLANGUAGES LangId, Boolean OCROrientImage, Boolean OCRstraightenImage)\r\n 在 D:\Vishnus\OCRConsole\OCRConsole\Program.cs:line 29\ 中的 OCRConsole.Program.Main(String[] args) r\n 在 System.AppDomain._nExecuteAssembly(程序集程序集,String[] args)\r\n 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String[] args)\r\n 在 Microsoft.VisualStudio.HostingProcess .HostProc.RunUsersAssembly()\r\n 在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n 在 System .Threading.ThreadHelper.ThreadStart()"

我可以知道我在这些方面提出的问题吗

4

0 回答 0