Barcode Image Generation Library

Introduction

This article and its code provides a way for developers to put barcodes into their applications. It allows for the generation of barcode images without the use of "barcode fonts". This need arose out 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.

To give an idea of what happens in this library: it first turns the data into a series of 1s and 0s representing equal-width bars and spaces. This string of binary information is then sent to a drawing function that converts it to an image representing the desired barcode. This approach allows for one common drawing method to be used on all symbologies.

Supported Encoding Types

Code 128 Code11 Code 39 (Extended / Full ASCII)
Code 93 EAN-8 EAN-13
UPC-A UPC-E JAN-13
MSI ISBN Standard 2 of 5
Interleaved 2 of 5 PostNet UPC Supplemental 2
UPC Supplemental 5 Codabar ITF-14
Telepen    

** Keep in mind that some symbologies go by more than one name, so make sure the one you are using isn't listed above by a different name before contacting me to add it. If it isn't listed above and you would like me to look at adding it to this library, please post a comment below, and I will take a look at it as soon as possible. (Bugs are always a priority, so please send me bug reports.)

Using the Code

The library contains a class called BarcodeLib. There are three constructors:

Copy Code
Barcode();Barcode(string);Barcode (string, BarcodeLib.TYPE);

If you decide to create an instance with parameters, the parameters are as follows: The string is the data to be encoded into the barcode, and the BarcodeLib.TYPE is the symbology to encode the data with. If you do not choose to specify the data and type at the time the instance is created, you may specify them through the appropriate property later on (but before you encode).

Copy Code
BarCodeLib.Barcode b = new BarCodeLib.Barcode(BarCodeLib.TYPE.UPCA,           "038000356216", Color.Black, Color.White, 300, 150);

To get the image representing the data generated, you must then call one of the many Encode functions.

代码
public Image Encode(TYPE iType, string StringToEncode, int Width,
int Height)
public Image Encode(TYPE iType, string StringToEncode, Color
ForeColor, Color BackColor,
int Width, int Height)
public Image Encode(TYPE iType, string StringToEncode, Color
ForeColor, Color BackColor)
public Image Encode(TYPE iType, string
StringToEncode)
Encode(TYPE iType)
Encode()

 

相关文章: