翻譯|使用教程|編輯:莫成敏|2019-08-23 11:52:23.210|閱讀 389 次
概述:LEADTOOLS Barcode Pro包含了開發人員需要檢測、讀取和寫入超過100種不同的1D和2D條形碼類型和子類型,如UPC、EAN、Code 128、QR Code、Data Matrix和PDF417等等。在這篇文章中,將討論如何智能地從掃描的文件中捕獲條形碼。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
LEADTOOLS (Lead Technology)由Moe Daher and Rich Little創建于1990年,其總部設在北卡羅來納州夏洛特。LEAD的建立是為了使Daher先生在數碼圖象與壓縮技術領域的發明面向市場。在29年的發展歷程中,LEAD以其在全世界主要國家中占有的市場領導地位,在數碼圖象開發工具領域中已成為既定的全球領導者。LEADTOOLS開發與發布的LEAD是屢獲殊榮的開發工具包。
LEADTOOLS Barcode Pro包含了開發人員需要檢測、讀取和寫入超過100種不同的1D和2D條形碼類型和子類型,如UPC、EAN、Code 128、QR Code、Data Matrix和PDF417等等。相比于市場上其他同類型的條形碼成像技術,LEADTOOLS Barcode Pro無疑是最好的。
智能捕獲可以指從圖像或文檔捕獲數據的幾種不同方式。在這篇文章中,將討論如何智能地從掃描的文件中捕獲條形碼。LEADTOOLS TWAIN SDK和條碼SDK是開發人員可以輕松地使用它來創建物理文檔的掃描應用程序,同時捕捉和提取發現的任何條形碼數據庫。
AIIM 最近的一項調查表明,32%的受訪公司使用智能捕獲技術從PDF和其他數字文檔中提取條形碼。說到這里,讓我們創建一個.NET桌面應用程序,它將識別掃描圖像中的條形碼。對于找到的每個條形碼,我們將提取數據,然后將該數據保存到文本文件,同時將掃描的文檔另存為PDF。
這個應用程序將只使用三個按鈕。一個用于選擇將保存PDF和TXT的輸出目錄,一個用于選擇要掃描的掃描儀,另一個用于執行掃描并識別條形碼。
SelectDir_Click
// Change the output directory using (FolderBrowserDialog dlg = new FolderBrowserDialog()) { dlg.ShowNewFolderButton = true; if (dlg.ShowDialog(this) == DialogResult.OK) _outputDirectory = System.IO.Path.GetFullPath(dlg.SelectedPath); }
ScannerSelect_Click
// Select the scanner to use _twainSession.SelectSource(null);
Scan_Read_Click
// Scan the new page(s) _twainSession.Acquire(TwainUserInterfaceFlags.Show);
現在添加以下變量。
private static BarcodeEngine engine = new BarcodeEngine(); private static BarcodeReader reader = engine.Reader; // The Twain session private static TwainSession _twainSession; // The output directory for saving PDF files private static string _outputDirectory; // The image processing commands we are going to use to clean the scanned image private static List<RasterCommand> _imageProcessingCommands; private static int _scanCount; private static StringBuilder sb;
在Form1_Load中,添加用于設置許可證的代碼、初始化新的Twain會話、訂閱TwainSession.Acquire事件,然后初始化任何圖像處理命令。
RasterSupport.SetLicense(@"", ""); _twainSession = new TwainSession(); _twainSession.Startup(this.Handle, "My Company", "My Product", "My Version", "My Application", TwainStartupFlags.None); _twainSession.AcquirePage += new EventHandler<TwainAcquirePageEventArgs>(_twainSession_AcquirePage); // Add as many as you like, here we will add Deskew and Despeckle _imageProcessingCommands = new List<RasterCommand>(); _imageProcessingCommands.Add(new DeskewCommand()); _imageProcessingCommands.Add(new DespeckleCommand());
在Form1_FormClosed中,結束TWAIN會話。
// End the twain session _twainSession.Shutdown();
最后添加Twain獲取句柄的代碼。
private void _twainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e) { _scanCount++; // We have a page RasterImage image = e.Image; // First, run the image processing commands on it foreach (RasterCommand command in _imageProcessingCommands) { command.Run(image); } // Read all the barcodes in this image BarcodeData[] barcodes = reader.ReadBarcodes(e.Image, LeadRect.Empty, 0, null); // Print out the barcodes we found sb = new StringBuilder(); sb.AppendLine($"Contains {barcodes.Length} barcodes"); for (int i = 0; i < barcodes.Length; i++) { BarcodeData barcode = barcodes[i]; sb.AppendLine($" {i + 1} - {barcode.Symbology} - {barcode.Value}"); } // Save string builder to a text file System.IO.File.WriteAllText($@"{_outputDirectory}\barcodes{_scanCount}.txt", sb.ToString()); // Save image as PDF using (RasterCodecs codecs = new RasterCodecs()) { codecs.Save(e.Image, $@"{_outputDirectory}\ScannedImage{_scanCount}.pdf", RasterImageFormat.RasPdf, 0); } }
想要購買LEADTOOLS產品正版授權,或了解更多產品信息請點擊
掃描關注慧聚IT微信公眾號,及時獲取最新動態及最新資訊
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn