private void _twain_AcquirePage(object sender, TwainAcquirePageEventArgs e) { // This event occurs for each page acquired using the Acquire method bool bTopMost = logWindow.TopMost; logWindow.TopMost = false; try { if (_twaintransferMode != TwainTransferMechanism.File) { if (e.Image != null) { Page page = new Page(); page.DeleteOnDispose = false; string strTemp = Path.GetTempFileName(); _codec.Save(e.Image, strTemp, Leadtools.RasterImageFormat.Tif, 0); page.FilePath = strTemp; twainImageCollection.Images.Add(new ListImageBox.ImageItem(_codec.Load(strTemp), twainImageCollection, page)); e.Image.Dispose(); } } else { MessageBox.Show(this, "Acquired page(s) is saved to file(s)", "Acquire to File"); } } catch (Exception ex) { AddErrorToErrorList(ex.Message); } logWindow.TopMost = bTopMost; }
private void _twain_AcquirePage(object sender, TwainAcquirePageEventArgs e) { try { if (_transferMode != TwainTransferMode.File) { if (e.Image != null) { _scanCount++; string childCaption; childCaption = string.Format("Twain Scanned page {0}", _scanCount.ToString()); if (_cleanupAfterAcquire) { ApplyDocumentCleanupCommands(e.Image); } CreateChildForm(e.Image, childCaption); } } else { MessageBox.Show(this, "Acquired page(s) is saved to file(s)", "Acquire to File"); } } catch (Exception ex) { AddErrorToErrorList(ex.Message); } }
private void _twain_AcquirePage(object sender, TwainAcquirePageEventArgs e) { // This event occurs for each page acquired using the Acquire method try { if (_transferMode != TwainTransferMechanism.File) { if (e.Image != null) { _scanCount++; string childCaption; childCaption = string.Format("Twain {0}{1}", DemosGlobalization.GetResxString(GetType(), "resx_ScannedPage"), _scanCount.ToString()); if (_cleanupAfterAcquire) { ApplyDocumentCleanupCommands(e.Image); } CreateChildForm(e.Image, childCaption); } } else { MessageBox.Show(this, DemosGlobalization.GetResxString(GetType(), "resx_AcquireToFileMsg"), DemosGlobalization.GetResxString(GetType(), "resx_AcquireToFile")); } } catch (Exception ex) { AddErrorToErrorList(ex.Message); } }
private void _twainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e) { if (!_canceled) { try { RasterImage image = e.Image; // Deskew the image DeskewCommand cmd = new DeskewCommand(); cmd.FillColor = Leadtools.Demos.Converters.FromGdiPlusColor(Color.White); cmd.Flags = DeskewCommandFlags.DocumentImage; cmd.Run(image); // Add the page to the OCR engine _document.Pages.AddPage(image, new OcrProgressCallback(OcrProgress)); } catch (Exception ex) { ShowError(ex); e.Cancel = true; } } // Check if we canceled if (_canceled) { e.Cancel = true; } }
void twainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e) { if (scannedImage == null) { scannedImage = e.Image.Clone(); } else { scannedImage.AddPage(e.Image.Clone()); } }
void twainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e) { if (_scannedImage != null) { _scannedImage.Dispose(); _scannedImage = null; } if (e.Image != null) { _scannedImage = e.Image.Clone(); } }
private void _twain_AcquirePage(object sender, TwainAcquirePageEventArgs e) { try { if (_transferMode != TwainCapabilityValue.TransferMechanismFile) { if (_cleanupAfterAcquire) { ApplyDocumentCleanupCommands(e.Image); } if (e.Image != null) { if (_viewer.Image == null) { _viewer.Image = e.Image; _miViewPrevious.Enabled = false; _miViewNext.Enabled = false; } else { _viewer.Image.AddPage(e.Image); _viewer.Image.Page = _viewer.Image.PageCount; _miViewPrevious.Enabled = true; _miViewNext.Enabled = false; } _miFileSave.Enabled = true; } } else { MessageBox.Show(this, "Acquired page(s) is saved to file(s)", "Acquire to File"); } } catch (Exception ex) { Messager.ShowError(this, ex); } }
private void Twain_AcquirePage(object sender, TwainAcquirePageEventArgs e) { string[] barDataArray = ReadBarcode(e.Image); //Check if Barcodes found if (barDataArray != null) { foreach (string barData in barDataArray) { if (barData != null && barData == _seperatorStringDlg.SeperatorString) { //If barData equals "Separator" string, save the image to a sperate file _saveFilesCount++; _twainSaveFileName = ChangeSaveFileName(_saveFilesCount.ToString()); } } } // Save the scanned images to the TwainSaveFileName file _codecs.Save(e.Image, _twainSaveFileName, RasterImageFormat.Tif, e.Image.BitsPerPixel, 1, 1, 1, CodecsSavePageMode.Append); //Add the scanned image to the viewer control if (_viewer.Image == null || _viewer.Image.PageCount == 0) { _viewer.Image = e.Image; } else { _viewer.Image.AddPage(e.Image); } }
/// <summary> /// Acquire page event /// </summary> private void _twain_AcquirePage(object sender, TwainAcquirePageEventArgs e) { try { if (e.Image != null) { if (_cleanupAfterAcquire) { ApplyDocumentCleanupCommands(e.Image); } // Check if the required file format supports multi-page if ((_fileFormat == RasterImageFormat.Tif) || (_fileFormat == RasterImageFormat.Ccitt) || (_fileFormat == RasterImageFormat.CcittGroup31Dim) || (_fileFormat == RasterImageFormat.CcittGroup32Dim) || (_fileFormat == RasterImageFormat.CcittGroup4) || (_fileFormat == RasterImageFormat.TifCmp) || (_fileFormat == RasterImageFormat.TifCmw) || (_fileFormat == RasterImageFormat.TifCmyk) || (_fileFormat == RasterImageFormat.TifCustom) || (_fileFormat == RasterImageFormat.TifJ2k) || (_fileFormat == RasterImageFormat.TifJbig) || (_fileFormat == RasterImageFormat.TifJpeg) || (_fileFormat == RasterImageFormat.TifJpeg411) || (_fileFormat == RasterImageFormat.TifJpeg422) || (_fileFormat == RasterImageFormat.TifLead1Bit) || (_fileFormat == RasterImageFormat.TifLzw) || (_fileFormat == RasterImageFormat.TifLzwCmyk) || (_fileFormat == RasterImageFormat.TifLzwYcc) || (_fileFormat == RasterImageFormat.TifPackBits) || (_fileFormat == RasterImageFormat.TifPackBitsCmyk) || (_fileFormat == RasterImageFormat.TifPackbitsYcc) || (_fileFormat == RasterImageFormat.TifUnknown) || (_fileFormat == RasterImageFormat.TifYcc) || (_fileFormat == RasterImageFormat.Gif)) { // save the acquired page in multi-page file. _codecs.Save(e.Image, _fileName, _fileFormat, _bitsPerPixel, 1, 1, 1, CodecsSavePageMode.Append); } else { // we are trying to save each page in a separate file // the extension of the file name string ext = string.Empty; // save the extension of the file name if it has one if (Path.HasExtension(_fileName)) { ext = Path.GetExtension(_fileName); } // save the file name with no indicates the page no. string tmpFileName = Path.GetFileNameWithoutExtension(_fileName); string tmpDirName = Path.GetDirectoryName(_fileName); string newFileName = string.Format("{0}\\{1}{2}{3}", tmpDirName, tmpFileName, _pageNo.ToString(), ext); _codecs.Save(e.Image, newFileName, _fileFormat, _bitsPerPixel); // increment the page count _pageNo++; } // Add the acquired page to the viewer if (_viewer.Image == null) { _viewer.Image = e.Image; } else { _viewer.Image.AddPage(e.Image); _viewer.Image.Page = _viewer.Image.PageCount; } } } catch (Exception ex) { Messager.ShowError(this, ex); } }
/// <summary> /// AcquirePageイベント処理 /// </summary> private void _twain_AcquirePage(object sender, TwainAcquirePageEventArgs e) { try { if (e.Image != null) { // 選択されているファイルフォーマットがマルチページに対応しているかどうかを確認します。 if ((_fileFormat == RasterImageFormat.Tif) || (_fileFormat == RasterImageFormat.Ccitt) || (_fileFormat == RasterImageFormat.CcittGroup31Dim) || (_fileFormat == RasterImageFormat.CcittGroup32Dim) || (_fileFormat == RasterImageFormat.CcittGroup4) || (_fileFormat == RasterImageFormat.TifCmp) || (_fileFormat == RasterImageFormat.TifCmw) || (_fileFormat == RasterImageFormat.TifCmyk) || (_fileFormat == RasterImageFormat.TifCustom) || (_fileFormat == RasterImageFormat.TifJ2k) || (_fileFormat == RasterImageFormat.TifJbig) || (_fileFormat == RasterImageFormat.TifJpeg) || (_fileFormat == RasterImageFormat.TifJpeg411) || (_fileFormat == RasterImageFormat.TifJpeg422) || (_fileFormat == RasterImageFormat.TifLead1Bit) || (_fileFormat == RasterImageFormat.TifLzw) || (_fileFormat == RasterImageFormat.TifLzwCmyk) || (_fileFormat == RasterImageFormat.TifLzwYcc) || (_fileFormat == RasterImageFormat.TifPackBits) || (_fileFormat == RasterImageFormat.TifPackBitsCmyk) || (_fileFormat == RasterImageFormat.TifPackbitsYcc) || (_fileFormat == RasterImageFormat.TifUnknown) || (_fileFormat == RasterImageFormat.TifYcc) || (_fileFormat == RasterImageFormat.Gif)) { // ファイル拡張子の保存変数を初期化します。 string ext = string.Empty; // ファイル名に拡張子を含んでいない場合、拡張子を追加します。 if (System.IO.Path.HasExtension(_fileName)) { ext = System.IO.Path.GetExtension(_fileName); } // 保存ファイル名に連番を付加します。 string tmpFileName = System.IO.Path.GetFileNameWithoutExtension(_fileName); string tmpDirName = System.IO.Path.GetDirectoryName(_fileName); string newFileName = string.Format("{0}\\{1}{2:000}{3}", tmpDirName, tmpFileName, _sFileNumber, ext); // 取得したページを保存します。 _codecs.Save(e.Image, newFileName, _fileFormat, _bitsPerPixel, 1, 1, 1, CodecsSavePageMode.Append); } else { // マルチページに対応していないフォーマットの場合、ファイルに番号を付加して保存します。 // ファイル拡張子の保存変数を初期化します。 string ext = string.Empty; // ファイル名に拡張子を含んでいない場合、拡張子を追加します。 if (System.IO.Path.HasExtension(_fileName)) { ext = System.IO.Path.GetExtension(_fileName); } // 保存ファイル名にページ番号を付加します。 string tmpFileName = System.IO.Path.GetFileNameWithoutExtension(_fileName); string tmpDirName = System.IO.Path.GetDirectoryName(_fileName); string newFileName = string.Format("{0}\\{1}{2:000}{3}", tmpDirName, tmpFileName, _pageNo, ext); _codecs.Save(e.Image, newFileName, _fileFormat, _bitsPerPixel); // ページ数のカウンタをインクリメントします。 _pageNo++; } // 取得ページをビューアに表示します。 if (_viewer.Image == null) { _viewer.Image = e.Image; } else { _viewer.Image.AddPage(e.Image); _viewer.Image.Page = _viewer.Image.PageCount; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }