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); } }
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); } }
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; }
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."); } }
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); } }
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(); } }
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; } } }