Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Barcodes play a crucial role in modern applications, facilitating efficient data tracking and management. In the world of .NET development, there numerous barcode generator SDK available and various extensions can be found on Visual Studio marketplace as well. IronBarcode stands out as a powerful library for generating and reading barcodes. How cool it would be to have a barcode generating .NET windows application using IronBarcode.
In this article, we will explore how to create a barcode generator in VB.NET using IronBarcode, a versatile tool that simplifies barcode handling within your applications.
IronBarcode, part of the Iron software product line, provides a comprehensive set of functionalities for working with barcodes in .NET applications. It supports various barcode formats, including QR codes, UPC, EAN, Code 128, and more. With its user-friendly API, IronBarcode makes it easy to generate barcodes, read, and customize them in VB.NET projects.
Features of IronBarcode:
Here are some important key features of IronBarcode that makes it a number one contender for generating barcodes in Visual Basic:
Set a name for your project and click "Next."
To integrate IronBarcode into your VB.NET project to generate linear barcodes, follow these steps:
NuGet Package Manager Console:
Install-Package BarCode
Now that IronBarcode is integrated in VB.NET console application, let's create barcode using IronBarcode that generates a barcode.
Importing Libraries:
Imports IronBarCode
Imports System.IO
Imports IronBarCode
Imports System.IO
In the first two lines, necessary libraries are imported. IronBarCode provides the functionality for working with barcodes, and System.IO is imported for handling input/output operations.
Creating a Simple Barcode:
Private myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
Private myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
Here, a barcode is created with the value "12345" and the encoding type EAN8 using BarcodeWriter.CreateBarcode method. The resulting barcode is stored in the myBarcode variable.
Saving the Barcode as an Image:
myBarcode.SaveAsImage("EAN8.jpeg")
myBarcode.SaveAsImage("EAN8.jpeg")
The generated barcode (myBarcode) is saved as an image file named "EAN8.jpeg" using the SaveAsImage method.
One-Liner for Creating and Saving Barcode:
BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8).ResizeTo(400, 100).SaveAsImage("EAN8.jpeg")
BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8).ResizeTo(400, 100).SaveAsImage("EAN8.jpeg")
This line combines the barcode creation, resizing (to 400x100), and saving into a single line of code.
Creating a barcode from binary data (byte array)
Dim payloadAsString As String = "This is some random string"
Dim payloadAsByteArray() As Byte = System.Text.Encoding.Default.GetBytes(payloadAsString)
Dim AztecBarcode = BarcodeWriter.CreateBarcode(payloadAsByteArray, BarcodeWriterEncoding.Aztec, 400, 400)
AztecBarcode.SaveAsImage("AztecBarcode.png")
Dim payloadAsString As String = "This is some random string"
Dim payloadAsByteArray() As Byte = System.Text.Encoding.Default.GetBytes(payloadAsString)
Dim AztecBarcode = BarcodeWriter.CreateBarcode(payloadAsByteArray, BarcodeWriterEncoding.Aztec, 400, 400)
AztecBarcode.SaveAsImage("AztecBarcode.png")
Here, we convert a string to a byte array (payloadAsByteArray) and then create a barcode (AztecBarcode) using the Aztec encoding type with dimensions 400x400.
Creating a barcode from binary data (MemoryStream)
Dim payloadAsStream As New MemoryStream(payloadAsByteArray)
Dim AztecBarcode2 = BarcodeWriter.CreateBarcode(payloadAsStream, BarcodeWriterEncoding.Aztec, 400, 400)
Dim payloadAsStream As New MemoryStream(payloadAsByteArray)
Dim AztecBarcode2 = BarcodeWriter.CreateBarcode(payloadAsStream, BarcodeWriterEncoding.Aztec, 400, 400)
In this step, we create a MemoryStream from the byte array and then generate another barcode (AztecBarcode2) using the Aztec encoding type with dimensions 400x400.
Saving the Barcode in multiple formats
MyBarCode.SaveAsImage("MyBarCode.png")
MyBarCode.SaveAsGif("MyBarCode.gif") MyBarCode.SaveAsHtmlFile("MyBarCode.html") MyBarCode.SaveAsJpeg("MyBarCode.jpg")
MyBarCode.SaveAsPdf("MyBarCode.Pdf")
MyBarCode.SaveAsPng("MyBarCode.png")
MyBarCode.SaveAsTiff("MyBarCode.tiff") MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp")
MyBarCode.SaveAsImage("MyBarCode.png")
MyBarCode.SaveAsGif("MyBarCode.gif") MyBarCode.SaveAsHtmlFile("MyBarCode.html") MyBarCode.SaveAsJpeg("MyBarCode.jpg")
MyBarCode.SaveAsPdf("MyBarCode.Pdf")
MyBarCode.SaveAsPng("MyBarCode.png")
MyBarCode.SaveAsTiff("MyBarCode.tiff") MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp")
These lines demonstrate how the generated barcode (MyBarCode) can be saved in various image formats such as PNG, GIF, HTML, JPEG, PDF, TIFF, and Windows Bitmap. IronBarcode provides flexibility in choosing the desired output format for the generated barcode.
Each step demonstrates different ways to create barcodes with IronBarcode, whether from simple values, binary data, or in a concise one-liner. The source code showcases the flexibility and ease of use offered by IronBarcode in VB Programming.
For more controlled barcode generation and styling, please visit this code examples page.
The complete Visual Basic sample code goes as follows:
Imports IronBarCode
Imports System.IO
Module Program
Sub Main(args As String())
' Creating a barcode is as simple as:
Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
' And save our barcode as an image:
myBarcode.SaveAsImage("EAN8.jpeg")
' OR, we can do both steps on one line:
BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8).ResizeTo(400, 100).SaveAsImage("EAN8.jpeg")
' Barcode can also be made from from Binary data (byte or stream)
Dim payloadAsString As String = "This is some random string"
Dim payloadAsByteArray() As Byte = System.Text.Encoding.Default.GetBytes(payloadAsString) ' Byte Array
Dim AztecBarcode = BarcodeWriter.CreateBarcode(payloadAsByteArray, BarcodeWriterEncoding.Aztec, 400, 400) ' Create from Byte Array
Dim payloadAsStream As New MemoryStream(payloadAsByteArray) ' MemoryStream
Dim AztecBarcode2 = BarcodeWriter.CreateBarcode(payloadAsStream, BarcodeWriterEncoding.Aztec, 400, 400) ' Create from Memory Stream
AztecBarcode.SaveAsImage("AztecBarcode.png")
End Sub
End Module
Imports IronBarCode
Imports System.IO
Module Program
Sub Main(args As String())
' Creating a barcode is as simple as:
Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
' And save our barcode as an image:
myBarcode.SaveAsImage("EAN8.jpeg")
' OR, we can do both steps on one line:
BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8).ResizeTo(400, 100).SaveAsImage("EAN8.jpeg")
' Barcode can also be made from from Binary data (byte or stream)
Dim payloadAsString As String = "This is some random string"
Dim payloadAsByteArray() As Byte = System.Text.Encoding.Default.GetBytes(payloadAsString) ' Byte Array
Dim AztecBarcode = BarcodeWriter.CreateBarcode(payloadAsByteArray, BarcodeWriterEncoding.Aztec, 400, 400) ' Create from Byte Array
Dim payloadAsStream As New MemoryStream(payloadAsByteArray) ' MemoryStream
Dim AztecBarcode2 = BarcodeWriter.CreateBarcode(payloadAsStream, BarcodeWriterEncoding.Aztec, 400, 400) ' Create from Memory Stream
AztecBarcode.SaveAsImage("AztecBarcode.png")
End Sub
End Module
Upon running the VB.NET console application, a barcode image file ("EAN8.jpeg") and a QR code type AztecBarcode image file ("AztecBarcode.png") will be created in the project folder.
IronBarcode can also be easily integrated to .NET Windows Forms and also ASP.NET Web projects.
In this article, we've explored how to create a VB.NET barcode generator using the IronBarcode library. By following the steps outlined, developers can seamlessly integrate barcode generation capabilities into their VB.NET applications, enhancing data tracking and management. IronBarcode's rich feature set and straightforward API make it a valuable tool for barcode-related tasks in the .NET ecosystem.
For more detailed information on IronBarcode and its usage, please visit the documentation page.
IronBarcode is free for development purposes, however it needs to be licensed to test out its full potential in handling barcode images in VB.NET Barcode applications. Download the library from here and give it a try.
9 .NET API products for your office documents