Esempio n. 1
0
        private void _btnRecognize_Click(object sender, EventArgs e)
        {
            try
            {
                using (WaitCursor wait = new WaitCursor())
                {
                    DocumentFormat format           = _documentFormatSelector.SelectedFormat;
                    String         documentFileName = _lblImageFileName.Text;

                    documentFileName = string.Concat(documentFileName, ".", DocumentWriter.GetFormatFileExtension(format));

                    _ocrPage.Recognize(null);
                    using (IOcrDocument _document = _ocrEngine.DocumentManager.CreateDocument(null, OcrCreateDocumentOptions.AutoDeleteFile))
                    {
                        _document.Pages.Add(_ocrPage);
                        _document.Save(documentFileName, format, null);
                    }

                    // Engine will correct the page deskew before AutoZone or Recognize, so we need to load the page again form the engine.
                    _viewer.Image = _ocrPage.GetRasterImage();
                    _viewer.Refresh();
                    UpdateMyControls();

                    // if the "View Final Document" option is checked then no need to show this message since
                    // it will load the saved document file.
                    if (!_cbViewFinalDocument.Checked)
                    {
                        Messager.ShowInformation(this, String.Format("The output document file was saved at ({0})", documentFileName));
                    }
                    else
                    {
                        if (File.Exists(documentFileName))
                        {
                            try
                            {
                                Process.Start(documentFileName);
                            }
                            catch
                            {
                                Messager.ShowError(this, "Unable to open generated results file with external viewing application");
                            }
                        }
                        else
                        {
                            Messager.ShowError(this, "Unable to open generated results file with external viewing application.\nThe system cannot find the file specified");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex.Message);
            }
        }
Esempio n. 2
0
        private void SetDocument(IOcrDocument ocrDocument, string documentFileName)
        {
            // Delete the old document if it exists
            if (_ocrDocument != null)
            {
                _ocrDocument.Dispose();
            }

            _lastDocumentFile = documentFileName;
            _ocrDocument      = ocrDocument;
            _ocrPage          = _ocrDocument.Pages[0];

            BuildWordLists();

            _wordTextBox.Text = string.Empty;

            SetImage(_ocrPage.GetRasterImage());

            UpdateUIState();
        }
Esempio n. 3
0
        bool LoadImage(string fileName)
        {
            try
            {
                RasterImage image = _codecs.Load(fileName);

                // Add the page first.
                _ocrPage = _ocrEngine.CreatePage(image, OcrImageSharingMode.None);

                // Add zones by default.
                AddZones(false);

                // Engine will correct the page deskew before AutoZone or Recognize, so we need to load the page again form the engine.
                _viewer.Image = _ocrPage.GetRasterImage();

                _viewer.Refresh();
                return(true);
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
                return(false);
            }
        }