此类库提供了一个易用的类,供那些需要根据字符串数据生成条形码图像的开发人员使用。
| C# (C# 2.0) |
<!-- Article Starts -->
简介本文及其代码为那些需要在应用程序中放置条形码的开发人员提供了一种方法。 它允许生成条形码图像,而无须使用“条码字体”。This need aroseout of the necessity for one of my own projects to use barcodes and the lack of free libraries on the web to do the job. 在此类库中给出了编码的思路。首先将数据转换为 1和 0 的等宽条形和空白描述 系列。 然后将二进制信息 字符串传递 到一个绘图函数,绘图函数将它转换为所需的条形码图像。这种方法可以作为一个通用的绘图方法,适用于所有的图像编码 。 代码使用此类库包含一个名为 Barcode 的类(BarcodeLib 命名空间)。Barcode 类有三个构造函数:
如果你决定使用参数创建此类的实例,参数如下:
如果在创建类的实例 时,没有指定编码数据和类型(参数),以后你可以通过设置适当的属性值来指定它们(但是需要在编码之前指定)。
要得到数据编码后生成的条形码图像,你必须调用下列的 Encode 函数之一:
在类中还包含更多的函数,你可以在编码后就把图像保存到文件中。
可以通过指定一个保存图像的位置全路径(包含文件名)字符串来使用此函数。第二个参数是一个枚举 ( 关注点在编写这个类库时,为我提供了这样一个机会:深入了解 条 形码编码方法的工作机制,以及编码方法之间的差异(While writting this library it offered me the chance to become intimately familiar with how barcode symbologies work and how the symbologies differ from one another)。 版本更新记录2007.10.10 - 初版 (存在 bug,并需要修改或实现某些编码法) (译者注:请读者关注作者的更新) 2007.10.16 -Encode_Code39() 函数修复了一个 bug(未包含 interchar spaces);更新了 Generate_Image(Color, Color) 函数,并把 using SetPixel 代码段替换 为下列代码 :
|