翻譯|使用教程|編輯:黃竹雯|2018-11-27 15:20:37.000|閱讀 432 次
概述:本系列教程會解答您在使用條形碼生成控件TBarCode SDK產品時遇到的絕大部分疑惑。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TBarCode SDK是一款可以在任意應用程序和打印機下生成和打印所有條碼的條碼軟件組件。TBarCode SDK對于Microsoft® Office 用戶以及軟件開發者提供條碼打印。使用此款條碼軟件組件您可以以完美效果生成和打印所有用于工業和商業條碼符號。
VB .NET中的以下示例代碼生成針對熱敏打印機輸出(分辨率如203 dpi)優化的條形碼圖像:
Dim bc As New TECIT.TBarCode.Barcode() bc.BarcodeType = TECIT.TBarCode.BarcodeType.EanUcc128 bc.Data = "1234567890123" ' set font size bc.Font = New System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Bold, GraphicsUnit.Point) bc.TextDistance = 1.1 bc.BearerBarType = TECIT.TBarCode.BearerBarType.TopAndBottom bc.BearerBarWidth = 2.4 ' adjust quiet zone in [Modules] (recommended for bitmaps) bc.QuietZoneUnit = TECIT.TBarCode.QuietZoneUnit.Modules bc.QuietZoneLeft = 12 bc.QuietZoneRight = 12 ' important: set printer resolution of thermal printer bc.Dpi = 203 ' 203 dpi --> Module Width = 0.5005 = 4 Pixel per Module Dim moduleWidth As New Single moduleWidth = 0.5004926 'need exact value here! bc.SizeMode = TECIT.TBarCode.SizeMode.CustomModuleWidth bc.ModuleWidth = moduleWidth + 0.001 bc.AdjustModuleWidthToPixelRaster = True Dim width As New Single Dim height As New Single ' size in [mm] width = bc.CalculateBarcodeWidth(Nothing) height = 35 ' convert size to [Pixels] width = width / (25.4 / bc.Dpi) height = height / (25.4 / bc.Dpi) ' adjust bitmap size Dim drawBitmapRect As New Rectangle(0, 0, width, height) bc.BoundingRectangle = drawBitmapRect ' output to file bc.Draw("barcode.bmp", TECIT.TBarCode.ImageType.Bmp)
C#ASP .NET中的以下示例代碼生成具有恒定大小的PDF417圖像:
//PDF417 Barcode barcode = new Barcode(); barcode.Data = strMyData; barcode.BarcodeType = BarcodeType.Pdf417; barcode.Pdf417.EncodingMode = PdfEncodingMode.Binary; // with dpi = 100 we get 1 Pixel = 0.254 mms barcode.Dpi = 100; // we should specify the number of horizontal data columns // this inhibits the symbol to change its horizontal size regardless of data barcode.Pdf417.NumberOfColumns = 16; // use a value, which fits to your available space !! // now calculate optimal bitmap size for the bar code barcode.SizeMode = SizeMode.FitToBoundingRectangle; Size optimalSize = barcode.CalculateOptimalBitmapSize(null, 1, 1); // we already could use this optimal Size for saving the image // barcode.BoundingRectangle = new Rectangle(0, 0, optimalSize.Width, optimalSize.Height); // barcode.Draw(filename, ImageType.Jpg); // but we want a constant bitmap size, // which fits exactly into your predefined space Size finalSize = new Size(350, 200); // final bitmap size in Pixel // so we have to add empty spaces around the symbol via adding a quiet zone barcode.QuietZoneUnit = QuietZoneUnit.Pixel; // calculate the required empty quiet zone we have to add if (finalSize.Width > optimalSize.Width) barcode.QuietZoneRight = finalSize.Width - optimalSize.Width; else // should not occur!! Reduce the Pdf417.NumberOfColumns finalSize.Width = optimalSize.Width; if (finalSize.Height > optimalSize.Height) barcode.QuietZoneBottom = finalSize.Height - optimalSize.Height; else // should not occur!! Increase final bitmap size finalSize.Height = optimalSize.Height; barcode.BoundingRectangle = new Rectangle(0, 0, finalSize.Width, finalSize.Height); barcode.Draw(filename, ImageType.Jpg);
選項1
將以下屬性添加到TBarCode .NET Web Control。這將生成一個優化的符號,適合120 x 120像素矩陣。如果需要,請增加“寬度/高度”和“NumberOfColumns”屬性。
<cc2:BarcodeControl id =“BarcodeControl1” Width =“120”Height =“120” Barcode-Dpi =“96” Barcode-SizeMode =“MinimalModuleWidth” Barcode-Pdf417-NumberOfColumns =“3” Barcode-MustFit =“True”ErrorHandling =“ShowMessage” Barcode-BarcodeType =“Pdf417”
選項#2
在頁面加載事件中或設置條形碼數據后,應用以下計算。此代碼將使用1:3的寬高比為圖形模塊。
Barcode barcode = BarcodeControl1.Barcode; barcode.SizeMode = SizeMode.FitToBoundingRectangle; System.Drawing.Size optimalSize = barcode.CalculateOptimalBitmapSize(null, 1, 1); BarcodeControl1.Width = new Unit(optimalSize.Width, UnitType.Pixel); BarcodeControl1.Height = new Unit(optimalSize.Height, UnitType.Pixel); BarcodeControl1.Refresh();
ASP .NET中的以下示例代碼生成Code 39圖像:
//Code 39 Barcode barcode = new Barcode(); barcode.Data = "10030000007611107871900002199908"; barcode.BarcodeType = BarcodeType.Code39; // with dpi = 100 we get 1 Pixel = 0.254 mms barcode.Dpi = 100; // bar code size should adapt to bounding rectangle barcode.SizeMode = SizeMode.FitToBoundingRectangle; // set default size of symbol (define the default height) barcode.BoundingRectangle = new Rectangle(0, 0, 254, 100 /* = 1 inch */); // now calculate optimal bitmap size for the bar code Size optimalSize = barcode.CalculateOptimalBitmapSize(null, 1, 1); // update rectangle to optimized size barcode.BoundingRectangle = new Rectangle(0, 0, optimalSize.Width, optimalSize.Height); barcode.Draw(filename, ImageType.Jpg);
以下C#.NET示例代碼向您展示了如何調整Data Matrix的設置:
Barcode barcode = new TECIT.TBarCode.Barcode(); barcode.BarcodeType = BarcodeType.DataMatrix; barcode.DataMatrix.Size = DataMatrixSize.Square26x26; barcode.DataMatrix.Format = DataMatrixFormat.Default; barcode.DataMatrix.ShallEnforceBinaryEncoding = true; barcode.SizeMode = SizeMode.CustomModuleWidth; barcode.ModuleWidth = 0.423; barcode.EncodingMode = EncodingMode.Hexadecimal; // set preformatted data (Bytes = Hex codes) barcode.Data = "444541080D02540BE3FF0052232D242D000065000000010100015A313031000000000000000000000000";
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn