翻譯|使用教程|編輯:李顯亮|2020-10-29 10:03:52.947|閱讀 797 次
概述:在本文中,將學(xué)習(xí)如何使用C#條碼讀取器API掃描和讀取條碼。本文還將介紹如何讀取圖像中特定或不同類型的條形碼符號。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
條形碼 技術(shù)是一種流行且廣泛使用的方式,以不同模式的形式直觀地表示有關(guān)對象的數(shù)據(jù)。條形碼是可以使用條形碼掃描儀解碼或讀取的數(shù)據(jù)的編碼形式和機器可讀形式 。如今,幾乎每種產(chǎn)品都包含條形碼,可以對其進行掃描以檢索有關(guān)該產(chǎn)品的信息。此外,越來越多的在線業(yè)務(wù)也影響了購買過程中不同類型條形碼的使用。
Aspose.BarCode是一個功能強大的庫,可以從任何角度從多種圖像類型生成和識別1D和2D條形碼。開發(fā)人員可以輕松地將條形碼生成和掃描功能添加到其.NET應(yīng)用程序中。
在上一篇文章中,學(xué)習(xí)了如何以編程方式生成各種類型的條形碼。在本文中,將學(xué)習(xí)如何使用C#條碼讀取器API掃描和讀取條碼。本文還將介紹如何讀取圖像中特定或不同類型的條形碼符號。
目前,Aspose.Barcode for .NET更新至20.10,還沒使用過的朋友可以點擊下載最新版Aspose.Barcode。(安裝包僅提供部分功能,并設(shè)置限制,如需試用完整功能請。)
以下是從圖像文件讀取1D或2D條形碼的步驟。
以下代碼示例顯示了如何使用C#掃描和讀取條形碼。
try
{
// Read file from directory
using (BarCodeReader reader = new BarCodeReader("Scan.jpg"))
{
foreach (BarCodeResult result in reader.ReadBarCodes())
{
// Read symbology type and code text
Console.WriteLine("Symbology Type: " + result.CodeType);
Console.WriteLine("CodeText: " + result.CodeText);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from //www.aspose.com/purchase/default.aspx.");
}
在某些情況下,您已經(jīng)知道要讀取的條形碼的符號體系。在這種情況下,您可以將條形碼的類型提供給BarCodeReader的對象。事先知道類型可以加快條形碼識別過程。以下代碼示例顯示了如何指定條形碼的類型。
try
{
// Create instance of BarCodeReader class
using (BarCodeReader reader = new BarCodeReader("Code128.jpg", DecodeType.Code128))
{
foreach (BarCodeResult result in reader.ReadBarCodes())
{
// Display code text and Symbology Type
Console.WriteLine("CodeText: " + result.CodeText);
Console.Write("Symbology Type: " + result.CodeType);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from //wwww.aspose.com/purchase/default.aspx.");
}
在特定情況下,您可能在單個圖像中放置了多個條形碼符號。在這種情況下,您可以配置API以一次性識別所有條形碼。以下是在單個圖像中讀取多個條形碼的步驟。
下面的代碼示例演示如何使用C#讀取單個圖像中的多個條形碼符號。
try
{
BaseDecodeType[] objArray = new BaseDecodeType[] { DecodeType.Code39Standard, DecodeType.Pdf417 };
// Initialize the BarCodeReader, Call Read() method in a loop and Display the codetext and symbology type
using (BarCodeReader reader = new BarCodeReader("RecognizingMultipleSymbologies.png", objArray))
{
foreach (BarCodeResult result in reader.ReadBarCodes())
{
Console.WriteLine("Codetext: " + result.CodeText);
Console.WriteLine("Symbology type: " + result.CodeType);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose BarCode License. You can purchase full license or get 30 day temporary license from //wwww.aspose.com/purchase/default.aspx.");
}
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn