Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Barcodes provide a clear and machine-readable way to present data. Initially, barcodes consisted of parallel lines with varying widths and spacing, serving as a representation of data. These traditional linear or one-dimensional (1D) barcodes could be scanned by specialized optical devices called barcode readers. However, the evolution of barcodes led to the invention of two-dimensional (2D) barcodes, also known as matrix codes. Unlike traditional barcodes, 2D barcodes utilize patterns such as rectangles, dots, and hexagons instead of bars. To read these 2D barcodes, specific optical scanner setups are available, or alternative methods involve using a digital camera connected to a computer running decoding software. Moreover, mobile devices like smartphones can leverage their integrated cameras and dedicated applications to function as a 2D barcode scanner.
Zebra Crossing, often known as ZXing, is an open-source, multi-format 1D/2D barcode image processing toolkit that was developed in Java and has ports for other languages. The core image decoding library, Java-specific client code, and the Android client Barcode Scanner are only a few of the modules that make up ZXing. Numerous more independent open-source projects are built upon it.
Open Visual Studio, choose "new project" from the file menu, then "console application". In this article, we are choosing the C# console app.
Enter the project name and the file path in the appropriate text box. Next, click the Create button to choose the required .NET Framework.
If you selected a console application, the project will now create its structure and open the program.cs file, allowing you to enter the program's code and build or execute it.
Enter the next command into the NuGet Package Manager Console.
Install-Package ZXing.Net.Bindings.Windows.Compatibility
Alternatively, we can get the item using the NuGet package manager tool. Like the illustration below. Try installing the first result you choose.
We are able to create a barcode using the below sample code. ZXing allows us to create more than 10 types of barcode format.
using ZXing.Windows.Compatibility;
var options = new QrCodeEncodingOptions
{
Width = 250,
Height = 250,
};
var writer = new BarcodeWriter();
writer.Format= BarcodeFormat.QR_CODE;
writer.Options = options;
System.Drawing.Bitmap _bitmap=writer.Write("Hello world");
_bitmap.Save("Demo1.png");
using ZXing.Windows.Compatibility;
var options = new QrCodeEncodingOptions
{
Width = 250,
Height = 250,
};
var writer = new BarcodeWriter();
writer.Format= BarcodeFormat.QR_CODE;
writer.Options = options;
System.Drawing.Bitmap _bitmap=writer.Write("Hello world");
_bitmap.Save("Demo1.png");
Imports ZXing.Windows.Compatibility
Private options = New QrCodeEncodingOptions With {
.Width = 250,
.Height = 250
}
Private writer = New BarcodeWriter()
writer.Format= BarcodeFormat.QR_CODE
writer.Options = options
Dim _bitmap As System.Drawing.Bitmap=writer.Write("Hello world")
_bitmap.Save("Demo1.png")
Above, we are setting the height and width for the QrCodeEncodingOptions
. Then we create an object for BarcodeWriter
. For the BarcodeWriter
, we are setting the barcode format as QR_Code. Then we assign the qrcode
option which we created earlier. The write function in the BarcodeWriter
encodes the given string into a barcode and returns the barcode as a bitmap image. Then, with the help of the save function in the bitmap, we can save the image. Below is the result from the code.
using ZXing.Windows.Compatibility;
var barcodeBitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile("demo.png");
var reader = new BarcodeReader();
var result = reader.Decode(barcodeBitmap);
if (result != null)
{
Console.WriteLine(result.Text);
Console.ReadKey();
}
using ZXing.Windows.Compatibility;
var barcodeBitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile("demo.png");
var reader = new BarcodeReader();
var result = reader.Decode(barcodeBitmap);
if (result != null)
{
Console.WriteLine(result.Text);
Console.ReadKey();
}
Imports ZXing.Windows.Compatibility
Private barcodeBitmap = CType(System.Drawing.Bitmap.FromFile("demo.png"), System.Drawing.Bitmap)
Private reader = New BarcodeReader()
Private result = reader.Decode(barcodeBitmap)
If result IsNot Nothing Then
Console.WriteLine(result.Text)
Console.ReadKey()
End If
In the above code, we first load the image into a bitmap. Then, we create a BarcodeReader
object. The Decode
function allows us to pass bitmap as a parameter, which can return the result into multiple types. Next, we use the Text
property to get the text encoded in the barcode.
With the help of this barcode library, reading and creating barcodes is straightforward. A dynamic barcode is easy to make with IronBarcode's Library. With just a few lines of code, this simple library can generate a barcode, which helps us to encode barcode images. IronBarcode enables us to generate barcodes in languages like C# and VB.NET.
To utilize the IronBarcode library in the solution, you must download the required package. To do this, utilize the package manager's code that is described below:
:PackageInstall
As an alternative, you can use the NuGet Package Manager, which will show all the search results, to seek and download the "Barcode" package. Then you can select the essential package to download into the program from them.
With just a few lines of code, we can quickly make barcode images using the IronBarcode library. Additionally, it enables us to save the created barcode as a separate picture file. Here is some sample Visual Basic code for creating a barcode label with a Console program.
using IronBarCode;
QRCodeWriter.CreateQrCode(textBox1.Text, 500, QRCodeWriter.QrErrorCorrectionLevel.Medium, 0).SaveAsPng("demo.png");
using IronBarCode;
QRCodeWriter.CreateQrCode(textBox1.Text, 500, QRCodeWriter.QrErrorCorrectionLevel.Medium, 0).SaveAsPng("demo.png");
Imports IronBarCode
QRCodeWriter.CreateQrCode(textBox1.Text, 500, QRCodeWriter.QrErrorCorrectionLevel.Medium, 0).SaveAsPng("demo.png")
A 500 by 500 pixel graphic is produced utilizing a medium level of error correction, and is then saved to a file location using the SaveAsPng
method.
The next code example reads the text encoded in the QR code that we created in the previous example.
var barcodeBitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile("demo.png");
var reader=IronBarCode.BarcodeReader.Read(barcodeBitmap);
Console.WriteLine(reader.Values()[0]);
Console.ReadKey();
var barcodeBitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile("demo.png");
var reader=IronBarCode.BarcodeReader.Read(barcodeBitmap);
Console.WriteLine(reader.Values()[0]);
Console.ReadKey();
Dim barcodeBitmap = CType(System.Drawing.Bitmap.FromFile("demo.png"), System.Drawing.Bitmap)
Dim reader=IronBarCode.BarcodeReader.Read(barcodeBitmap)
Console.WriteLine(reader.Values()(0))
Console.ReadKey()
We first load the image into a bitmap, and then read the image using the Read
method on the BarcodeReader
class. We use the Values
property on the BarcodeResults
object returned from the Read
method to get the content that was read from the QR code.
To know more about ZXing and how it compares with IronBarcode, read this next blog post.
Our Reading Barcodes tutorial also provides more information about how to use IronBarcode to read barcodes and QR codes. For more code tutorials on IronBarcode.
ZXing barcode scanner can create high-quality barcodes, but it is outdated and supports few barcode formats. It also has limited documentation and product support.
On the other hand, IronBarcode is very efficient and flexible, and is able to work on many operating systems. IronBarcode can change the color, size, spacing, and lettering used in barcodes. It also supports Crystal Reports.
Developers can use IronBarcode for free. Users can purchase a license to access additional features and receive a full year of support and product updates.
9 .NET API products for your office documents