Generating Barcode in C#

Introduction:
 
In this article we will learn hot to generate barcode from C# windows application using QRCODE GENERATOR LIBRARY.
 
Background:

In so many situation we need to generate the barcode images for products using C# we can generate this barcode images and print on the products then after we can scan those barcode image and get the description like price,image etc... from the database.

Here I'll discuss how to generate the barcode using C#.

What Is Barcode?

Barcode or Qrcode is the technique to encode the data ex. Text,url or etc into encoded image format to provide confidential access to the data. In shopping malls you may see they are scaning those barcode prited on products and then get the description of the perticuler product from their server database. For those kind of activity we have to generate those barcode.

Here we will learn to generate barcode as well as qrcode images also.

Let's take a look step by step.

Step 1: Download QRCODE GENERATOR LIBRARY from onbarcode.com.

Step 2: Open Visual Studio - Create New Project - Windows Form.

Step 3: Add reference to OnBarcode.Barcode.Winforms.dll.

Step 4: Design form with some input fields for accepting data to encode and the targeted location to save barcode generated image.

Step 5: To generate Barcode as well as Qrcode images write two differen methods as follows.

        private void GenerateBacode(string _data, string _filename)
        {
            Linear barcode = new Linear();
            barcode.Type = BarcodeType.CODE11;
            barcode.Data = _data;
            barcode.drawBarcode(_filename);
        }
        private void GenerateQrcode(string _data, string _filename)
        {
            QRCode qrcode = new QRCode();
            qrcode.Data = _data;
            qrcode.DataMode = QRCodeDataMode.Byte;
            qrcode.UOM = UnitOfMeasure.PIXEL;
            qrcode.X = 3;
            qrcode.LeftMargin = 0;
            qrcode.RightMargin = 0;
            qrcode.TopMargin = 0;
            qrcode.BottomMargin = 0;
            qrcode.Resolution = 72;
            qrcode.Rotate = Rotate.Rotate0;
            qrcode.ImageFormat = ImageFormat.Gif;
            qrcode.drawBarcode(_filename);
        }


Conclusion:

In this way you can generate barcode and qrcode images in C#. Output will look like bellow

Barcode:

Barcode in C#

Qrcode:

qrcode in C#

Up Next
    Ebook Download
    View all
    Learn
    View all