原創(chuàng)|使用教程|編輯:龔雪|2013-12-16 09:34:20.000|閱讀 954 次
概述:本文主要介紹LEADTOOLS Barcode的技術(shù)亮點(diǎn)和用法。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
LEADTOOLS可以準(zhǔn)確而快速地讀取各種一維和二維條碼(類型)及其子類型。LEADTOOLS Barcode支持100多種條形碼的讀寫,其中包括所有主要的1D和2D條形碼。
LEADTOOLS Barcode SDK技術(shù)亮點(diǎn):
使用LEADTOOLS Barcode
LEADTOOLS Barcode支持可以通過Leadtools.Barcode.dll程序集來訪問。實(shí)際讀/寫的條形碼包含在動(dòng)態(tài)加載和運(yùn)行時(shí)訪問的單獨(dú)程序集中。這些組件是原生.NET和Silverlight二進(jìn)制文件,可以直接添加到您的項(xiàng)目作為部署的參考。下表列出來?xiàng)l碼支持的程序集以及功能:
讀取條形碼
要讀取條碼,首選需要獲取存儲(chǔ)在BarcodeEngine.Reader屬性中的Leadtools.Barcode.BarcodeReader對象實(shí)例。然后調(diào)用BarcodeReader.ReadBarcode 或BarcodeReader.ReadBarcodes方法以傳遞Leadtools.RasterImage對象。這些方法會(huì)返回一個(gè)或一個(gè)包含了條形碼數(shù)據(jù)的Leadtools.Barcode.BarcodeData對象的數(shù)組。
// Read all barcodes in the image BarcodeData[] dataArray = barcodeEngineInstance.Reader.ReadBarcodes( theImage, \\ The RasterImage object LogicalRectangle.Empty, \\ Search rectangle, Empty means all image 0, \\ Maximum number of barcodes to return, 0 means all barcodes found null); \\ Array of BarcodeSymbology we are interested in, null means all
當(dāng)找到條形碼或發(fā)生錯(cuò)誤時(shí),BarcodeReader.ReadSymbology事件被激活。 Leadtools.Barcode.BarcodeSymbology枚舉中定義了所支持的條形碼枚舉類型。 下列代碼片段可搜索并試圖從圖像中讀取單個(gè)QR碼:
BarcodeData data = barcodeEngineInstance.Reader.ReadBarcode( theImage, \\ The RasterImage object LogicalRectangle.Empty, \\ Search rectangle, Empty means all image BarcodeSymbology.QR); \\ Symbology, only QR
通過傳遞Leadtools.Barcode.BarcodeReadOptions中的一個(gè)或者多個(gè)對象,微調(diào)條形碼讀取。例如,改變條形碼閱讀器的默認(rèn)選項(xiàng),將搜索方向改為水平方向和垂直于條形碼PDF417,示例如下:
// Get the default PDF417 read options PDF417BarcodeReadOptions options = barcodeEngineInstance.Reader.GetDefaultOptions(BarcodeSymbology.PDF417); // Change the search direction options.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; // Read a PDF417 barcode from the image BarcodeData data = barcodeEngineInstance.Reader.ReadBarcode(theImage, LogicalRectangle.Empty, BarcodeSymbology.PDF417);
編寫條形碼
要將條形碼寫入圖像中,首先需要獲取儲(chǔ)存在BarcodeEngine.Writer屬性中的Leadtools.Barcode.BarcodeWriter對象實(shí)例。然后傳遞 Leadtools.RasterImage對象以調(diào)用BarcodeWriter.WriterBarcode,代碼如下:
// Create a UPC A barcode BarcodeData data = new BarcodeData(); data.Symbology = BarcodeSymbology.UPCA; data.Value = "01234567890"; data.Bounds = new LogicalRectangle(10, 10, 600, 200, LogicalUnit.Pixel); // Write it with default options barcodeEngineInstance.Writer.WriteBarcode(theImage, data, null);
使用一個(gè)或多個(gè)Leadtools.Barcode.BarcodeWriteOptions衍生類添加額外功能至編寫操作中。下列代碼可使后續(xù)的所有編寫操作能顯示出條形碼文本:
OneDBarcodeWriteOptions options = barcodeEngineInstance.Writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions; options.TextPosition = OneDBarcodeTextPosition.Default; // Write it with default options barcodeEngineInstance.Writer.WriteBarcode(theImage, data, null);
編寫條碼時(shí),你可能想要計(jì)算條形碼的像素尺寸,并在提交前進(jìn)行微調(diào)。可使用BarcodeWriter.CalculateBarcodeDataBounds方法來實(shí)現(xiàn)這一點(diǎn)。
條碼類型
LEADTOOLS支持讀寫以下條碼類型:
每個(gè)主要條碼類型下包含一個(gè)或者多個(gè)條碼分類,如:
線性(1D)條碼:
2D:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)