Exemple #1
0
        public void LoadImageScanner()
        {
            if (!DemosGlobal.CheckKnown3rdPartyTwainIssues(this, twainSession.SelectedSourceName()))
            {
                return;
            }

            bool showUI = false;

            inTwainAcquire = true;

            //Set the scanner to scan a specified number of pages, scan at 1bpp B/W, and at 300DPI
            try
            {
                twainSession.MaximumTransferCount = 1;
                twainSession.Resolution           = new SizeF(300, 300);
            }
            catch
            {
                MessageBox.Show("Unable to set scanner to 300DPI.");
                showUI = true;
            }

            if (showUI)
            {
                twainSession.Acquire(TwainUserInterfaceFlags.Modal);
            }
            else
            {
                twainSession.Acquire(TwainUserInterfaceFlags.None);
            }

            inTwainAcquire = false;
        }
Exemple #2
0
        private void _btnAcquirePage_Click(object sender, EventArgs e)
        {
            if (scannedImage != null)
            {
                scannedImage.Dispose();
                scannedImage = null;
            }

            try
            {
                Messager.Show(this, "For best results, scan at 150DPI (or higher) and 1 bits per pixel", MessageBoxIcon.Information, MessageBoxButtons.OK);

                StartupTwain();

                if (!DemosGlobal.CheckKnown3rdPartyTwainIssues(this, twainSession.SelectedSourceName()))
                {
                    return;
                }

                if (twainSession.SelectSource(String.Empty) == DialogResult.OK)
                {
                    twainSession.Acquire(TwainUserInterfaceFlags.Show);
                }

                if (twainSession != null)
                {
                    twainSession.Shutdown();
                }
            }
            catch (Exception exp)
            {
                Messager.ShowError(this, exp);
            }
        }
Exemple #3
0
        private void Acquire(bool cleanup)
        {
            try
            {
                SetTransferMode();

                if (!DemosGlobal.CheckKnown3rdPartyTwainIssues(this, _twainSession.SelectedSourceName()))
                {
                    return;
                }

                _cleanupAfterAcquire = cleanup;
                if (_cleanupAfterAcquire)
                {
                    ShowCleanUpMessage();
                }

                // Acquire one or more images from a TWAIN source.
                _twainSession.Acquire(TwainUserInterfaceFlags.Show | TwainUserInterfaceFlags.Modal);
            }
            catch (Exception ex)
            {
                AddErrorToErrorList(ex.Message);
                MessageBox.Show(this, ex.Message);
            }
        }
Exemple #4
0
        /// <summary>
        /// スキャナより勤務票をスキャンして画像を取得します
        /// </summary>
        private void ScanOcr()
        {
            //出力先パス初期化
            _ocrPath = string.Empty;

            try
            {
                RasterSaveDialogFileFormatsList saveDlgFormatList = new RasterSaveDialogFileFormatsList(RasterDialogFileFormatDataContent.User);

                string tifPath = Properties.Settings.Default.PathInst + Properties.Settings.Default.PathSCAN;
                _fileName = tifPath + string.Format("{0:0000}", DateTime.Today.Year) +
                            string.Format("{0:00}", DateTime.Today.Month) +
                            string.Format("{0:00}", DateTime.Today.Day) +
                            string.Format("{0:00}", DateTime.Now.Hour) +
                            string.Format("{0:00}", DateTime.Now.Minute) +
                            string.Format("{0:00}", DateTime.Now.Second) + ".tif";

                ///以下、TWAIN取得関連 //////////////////////////////////////////////////////////////////////

                _fileFormat   = RasterImageFormat.CcittGroup4;
                _bitsPerPixel = 1;

                string pathName = System.IO.Path.GetDirectoryName(_fileName);
                if (System.IO.Directory.Exists(pathName))
                {
                    // ページカウンタを初期化します。
                    _pageNo = 1;

                    // 出力ファイルカウンタをインクリメントします。
                    _sFileNumber++;

                    // AcquirePageイベントハンドラを設定します。
                    _twainSession.AcquirePage += new EventHandler <TwainAcquirePageEventArgs>(_twain_AcquirePage);

                    // Acquire pages
                    _twainSession.Acquire(TwainUserInterfaceFlags.Show);

                    // AcquirePageイベントハンドラを削除します。
                    _twainSession.AcquirePage -= new EventHandler <TwainAcquirePageEventArgs>(_twain_AcquirePage);
                }
                else
                {
                    MessageBox.Show("ファイル名の書式が正しくありません。");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                _twainSession.Shutdown();
                _twainSession.Startup(this, "GrapeCity Inc.", "LEADTOOLS", "Ver.16.5J", "LEADTOOLS TWAIN 取得 サンプル", TwainStartupFlags.None);
            }
            finally
            {
                UpdateStatusBarText();
            }
        }
Exemple #5
0
        private void _menuItemFileAcuire_Click(object sender, EventArgs e)
        {
            if (!DemosGlobal.CheckKnown3rdPartyTwainIssues(this, _twnSession.SelectedSourceName()))
            {
                return;
            }

            if (Directory.Exists(_twainSaveFilePath))
            {
                using (WaitCursor cursor = new WaitCursor())
                {
                    try
                    {
                        if (_viewer.Image != null)
                        {
                            _viewer.Image.Dispose();
                        }

                        _twainSaveFileName = ChangeSaveFileName(_saveFilesCount.ToString());
                        //Call the Acquire method to start the scanning process
                        if (_twnSession.Acquire(TwainUserInterfaceFlags.Show) != DialogResult.OK)
                        {
                            Messager.ShowError(this, "Error Acquiring From Source");
                        }
                        else
                        {
                            _saveFilesCount++;
                            _twainSaveFileName = ChangeSaveFileName(_saveFilesCount.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        Messager.ShowError(this, ex.Message);
                    }
                    finally
                    {
                        UpdateControls();
                        UpdateStatusBarText();
                    }
                }
            }
            else
            {
                Messager.ShowError(this, "Set Results Path please.");
            }
        }
Exemple #6
0
        protected override void Run()
        {
            Progress(101, "Acquiring from scanner...");

            RasterImage image = null;// = twainSession.AcquireToImage(TwainUserInterfaceFlags.Show | TwainUserInterfaceFlags.Modal);

            SetTransferMode();

            twainSession.Acquire(TwainUserInterfaceFlags.Show | TwainUserInterfaceFlags.Modal);

            using (RasterCodecs codecs = MainForm.GetRasterCodecs())
            {
                codecs.Save(image, saveLocation, format, 0);
            }

            image.Dispose();

            base.Run();
        }
Exemple #7
0
        private void Acquire(bool cleanup)
        {
            try
            {
                if (!DemosGlobal.CheckKnown3rdPartyTwainIssues(this, _twainSession.SelectedSourceName()))
                {
                    return;
                }

                _cleanupAfterAcquire = cleanup;

                if (_cleanupAfterAcquire)
                {
                    ShowCleanUpMessage();
                }

                _twainSession.Acquire(TwainUserInterfaceFlags.Show | TwainUserInterfaceFlags.Modal);
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
        }
Exemple #8
0
        private void _miTwainAcquire_Click(object sender, System.EventArgs e)
        {
            bool bTopMost = logWindow.TopMost;

            logWindow.TopMost = false;
            try
            {
                SetTransferMode();
                // Acquire one or more images from a TWAIN source.
                twainImageCollection = new ListImageBox.ImageCollection("Twain Aquire");
                _twainSession.Acquire(TwainUserInterfaceFlags.Show | TwainUserInterfaceFlags.Modal);
            }
            catch (Exception ex)
            {
                AddErrorToErrorList(ex.Message);
                MessageBox.Show(this, ex.Message);
            }
            if (twainImageCollection.Images.Count > 0)
            {
                _lstBoxPages.AddImageCollection(twainImageCollection);
            }

            logWindow.TopMost = bTopMost;
        }
Exemple #9
0
        private void Acquire(bool cleanup)
        {
            try
            {
                if (!DemosGlobal.CheckKnown3rdPartyTwainIssues(this, _twainSession.SelectedSourceName()))
                {
                    return;
                }

                // get the output file name and file format
                RasterSaveDialog dlg = new RasterSaveDialog(_codecs);

                dlg.Title           = "File Acquire Path";
                dlg.AutoProcess     = false;
                dlg.EnableSizing    = true;
                dlg.FileFormatsList = new RasterSaveDialogFileFormatsList(RasterDialogFileFormatDataContent.Default);
                dlg.ShowFileOptionsBasicJ2kOptions = false;
                dlg.ShowFileOptionsJ2kOptions      = false;
                dlg.ShowFileOptionsMultipage       = false;
                dlg.ShowFileOptionsProgressive     = false;
                dlg.ShowFileOptionsQualityFactor   = false;
                dlg.ShowFileOptionsStamp           = false;
                dlg.ShowHelp          = false;
                dlg.ShowOptions       = false;
                dlg.ShowQualityFactor = false;

                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    // save the output file name
                    _fileName = dlg.FileName;

                    // save the output file format
                    _fileFormat   = dlg.Format;
                    _bitsPerPixel = dlg.BitsPerPixel;

                    string pathName = Path.GetDirectoryName(_fileName);
                    if (Directory.Exists(pathName))
                    {
                        // initialize the page counter
                        _pageNo = 0;

                        // Add the Acquire page event.
                        _twainSession.AcquirePage += new EventHandler <TwainAcquirePageEventArgs>(_twain_AcquirePage);
                        // Acquire pages

                        _cleanupAfterAcquire = cleanup;

                        if (_cleanupAfterAcquire)
                        {
                            ShowCleanUpMessage();
                        }

                        _twainSession.Acquire(TwainUserInterfaceFlags.Show);
                        // Remove the Acquire page event.
                        _twainSession.AcquirePage -= new EventHandler <TwainAcquirePageEventArgs>(_twain_AcquirePage);
                    }
                    else
                    {
                        Messager.ShowError(this, "Invalid File Name");
                    }
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
            finally
            {
                UpdateMyControls();
                UpdateStatusBarText();
            }
        }
Exemple #10
0
        private void DoWork()
        {
            if (!DemosGlobal.CheckKnown3rdPartyTwainIssues(this, _twainSession.SelectedSourceName()))
            {
                _canceled    = true;
                DialogResult = DialogResult.Cancel;
                return;
            }

            // Create an OCR document
            // Acquire the page(s)
            // Deskew the page
            // Add the pages to the engine
            // Recognize
            // Save to final document

            _lblProcessing.Text = "Acquiring a page...";

            _canceled = false;

            _twainSession.AcquirePage += new EventHandler <TwainAcquirePageEventArgs>(_twainSession_AcquirePage);

            try
            {
                if (!_canceled)
                {
                    DialogResult res = _twainSession.Acquire(TwainUserInterfaceFlags.Show);
                    if (res != DialogResult.OK && _document.Pages.Count <= 0)
                    {
                        _canceled = true;
                    }
                }

                if (_document.Pages.Count > 0)
                {
                    // We have the pages in the OCR engine, recognize them
                    if (!_canceled)
                    {
                        _document.Pages.Recognize(new OcrProgressCallback(OcrProgress));
                    }
                    if (!_canceled)
                    {
                        _document.Save(_documentFileName, _format, new OcrProgressCallback(OcrProgress));
                    }

                    // Show the final document
                    if (!_canceled && File.Exists(_documentFileName))
                    {
                        Process.Start(_documentFileName);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                // Unhook from the twain events
                _twainSession.AcquirePage -= new EventHandler <TwainAcquirePageEventArgs>(_twainSession_AcquirePage);

                // Remove all the pages from the document
                _document.Pages.Clear();
                _document.Dispose();

                if (!_canceled)
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    DialogResult = DialogResult.Cancel;
                }
            }
        }