彩票走势图

条形码控件TBarCode SDK系列教程九(TBarCode .NET篇)

翻译|使用教程|编辑:黄竹雯|2018-11-27 15:20:37.000|阅读 379 次

概述:本系列教程会解答您在使用条形码生成控件TBarCode SDK产品时遇到的绝大部分疑惑。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

TBarCode SDK是一款可以在任意应用程序和打印机下生成和打印所有条码的条码软件组件。TBarCode SDK对于Microsoft® Office 用户以及软件开发者提供条码打印。使用此款条码软件组件您可以以完美效果生成和打印所有用于工业和商业条码符号。

TBarCode SDK最新版下载

一. 如何创建针对Thermal Printers(热敏打印机)优化的位图?

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)

二. 如何创建具有恒定大小的可读PDF417位图?

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);

三. 如何在ASP.NET Web控件中优化PDF417符号?

选项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();

四. 如何创建可读代码39位图?

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);

五. 如何为DP Premiumadress创建26x26数据矩阵?

以下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";

标签:条形码条形码生成物联网工业4.0工业物联网

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP