Articles in this section
Category / Section

How to convert barcode to image using C# and VB.NET

4 mins read

Syncfusion Essential Barcode control is used to create various types of barcodes. Using this control, you can export barcode as image without GUI interfaces using C# and VB.NET.

Steps to export barcode as image programmatically:

  1. Create a new C# Windows Forms application project.

Create console application in visual studio

  1. Install the Syncfusion.SfBarcode.Windows NuGet package as reference to your .NET Framework application from NuGet.org.

Refer NuGet package to the project

  1. Include the following namespaces in the Form1.Designer.cs file.

C#

using Syncfusion.Windows.Forms.Barcode;
using System.Drawing;

         

           VB.NET

Imports Syncfusion.Windows.Forms.Barcode
Imports System.Drawing

 

  1. Use the following code snippet to export barcode to image without using any GUI interfaces.

C#

//Create a new Barcode control
SfBarcode barcode = new SfBarcode();
//Set the barcode text
barcode.Text = "Syncfusion Essential Studio Enterprise edition $995";
//Set the barcode type
barcode.Symbology = BarcodeSymbolType.QRBarcode;
//Set dimension for each block
QRBarcodeSetting setting = new QRBarcodeSetting();
setting.XDimension = 6;
barcode.SymbologySettings = setting;
//Export to image
Image img = barcode.ToImage();
//Save the image
img.Save("QRBarcode.png", System.Drawing.Imaging.ImageFormat.Png);
//Dispose the control
barcode.Dispose();

           

           VB.NET

'Create a new Barcode control
Dim barcode As SfBarcode = New SfBarcode()
'Set the barcode text
barcode.Text = "Syncfusion Essential Studio Enterprise edition $995"
'Set the barcode type
barcode.Symbology = BarcodeSymbolType.QRBarcode
Dim setting As QRBarcodeSetting = New QRBarcodeSetting()
setting.XDimension = 6
barcode.SymbologySettings = setting
Dim img As Image = barcode.ToImage()
'Save the image
img.Save("QRBarcode.png", System.Drawing.Imaging.ImageFormat.Png)
'Dispose the control
barcode.Dispose()
Process.Start("QRBarcode.png")

 

A complete working sample can be downloaded from ConvertBarcodeToImage.zip.

By executing the program, you will get the PNG image as follows.

Output barcode image.

Take a moment to peruse the documentation for Barcode, where you will find other options like creating one and two dimensional barcodes.

Refer here to explore the Syncfusion Essential Barcode control for Windows Forms.

An online sample link to create one and two dimensional barcode.

 

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied