Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this video tutorial, we delve into the process of reading barcodes using the Iron Barcode Library in conjunction with System.Drawing objects. The session begins by ensuring the Iron Barcode Library is installed via the NuGet package manager. Moving on to the Program.cs
file, we import essential namespaces: Iron Barcode for barcode functionality and Iron Software.Drawing for image handling.
We then initialize a list of AnyBitmap
to hold the barcodes, loading a barcode image as a System.Drawing.Bitmap
and casting it into an AnyBitmap
object. This is followed by adding the image to the barcode list. Similarly, a QR code image is loaded and added to the list. Iterating through the list, each barcode is read using the ReadBarcode
method, which returns detected barcodes that are printed on the console.
The tutorial showcases the ease of using Iron Barcode, highlighting its seamless integration with System.Drawing objects and its support for implicit casting. By the end of the tutorial, the program successfully detects and prints the values of the barcodes and QR codes, with each value corresponding to the data encoded within. The tutorial concludes with an invitation to the audience to try out the software by downloading it from the website.
using IronBarCode;
using IronSoftware.Drawing;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace BarcodeReaderExample
{
class Program
{
static void Main(string[] args)
{
// List to hold AnyBitmap objects containing barcode images
List<AnyBitmap> barcodeImages = new List<AnyBitmap>();
// Load a barcode image and convert it to AnyBitmap
Bitmap barcodeImage = (Bitmap)Image.FromFile("barcode.png");
AnyBitmap anyBitmapBarcode = (AnyBitmap)barcodeImage;
barcodeImages.Add(anyBitmapBarcode);
// Load a QR code image and convert it to AnyBitmap
Bitmap qrCodeImage = (Bitmap)Image.FromFile("qrcode.png");
AnyBitmap anyBitmapQRCode = (AnyBitmap)qrCodeImage;
barcodeImages.Add(anyBitmapQRCode);
// Iterate through the list of AnyBitmap images and read barcodes
foreach (AnyBitmap bitmap in barcodeImages)
{
// Read the barcode from the image
var barcodes = BarcodeReader.ReadBarcodes(bitmap);
// Output each barcode and its type
foreach (var barcode in barcodes)
{
Console.WriteLine($"Detected Barcode: {barcode.Text}, Type: {barcode.BarcodeFormat}");
}
}
}
}
}
using IronBarCode;
using IronSoftware.Drawing;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace BarcodeReaderExample
{
class Program
{
static void Main(string[] args)
{
// List to hold AnyBitmap objects containing barcode images
List<AnyBitmap> barcodeImages = new List<AnyBitmap>();
// Load a barcode image and convert it to AnyBitmap
Bitmap barcodeImage = (Bitmap)Image.FromFile("barcode.png");
AnyBitmap anyBitmapBarcode = (AnyBitmap)barcodeImage;
barcodeImages.Add(anyBitmapBarcode);
// Load a QR code image and convert it to AnyBitmap
Bitmap qrCodeImage = (Bitmap)Image.FromFile("qrcode.png");
AnyBitmap anyBitmapQRCode = (AnyBitmap)qrCodeImage;
barcodeImages.Add(anyBitmapQRCode);
// Iterate through the list of AnyBitmap images and read barcodes
foreach (AnyBitmap bitmap in barcodeImages)
{
// Read the barcode from the image
var barcodes = BarcodeReader.ReadBarcodes(bitmap);
// Output each barcode and its type
foreach (var barcode in barcodes)
{
Console.WriteLine($"Detected Barcode: {barcode.Text}, Type: {barcode.BarcodeFormat}");
}
}
}
}
}
Imports IronBarCode
Imports IronSoftware.Drawing
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Namespace BarcodeReaderExample
Friend Class Program
Shared Sub Main(ByVal args() As String)
' List to hold AnyBitmap objects containing barcode images
Dim barcodeImages As New List(Of AnyBitmap)()
' Load a barcode image and convert it to AnyBitmap
Dim barcodeImage As Bitmap = CType(Image.FromFile("barcode.png"), Bitmap)
Dim anyBitmapBarcode As AnyBitmap = CType(barcodeImage, AnyBitmap)
barcodeImages.Add(anyBitmapBarcode)
' Load a QR code image and convert it to AnyBitmap
Dim qrCodeImage As Bitmap = CType(Image.FromFile("qrcode.png"), Bitmap)
Dim anyBitmapQRCode As AnyBitmap = CType(qrCodeImage, AnyBitmap)
barcodeImages.Add(anyBitmapQRCode)
' Iterate through the list of AnyBitmap images and read barcodes
For Each bitmap As AnyBitmap In barcodeImages
' Read the barcode from the image
Dim barcodes = BarcodeReader.ReadBarcodes(bitmap)
' Output each barcode and its type
For Each barcode In barcodes
Console.WriteLine($"Detected Barcode: {barcode.Text}, Type: {barcode.BarcodeFormat}")
Next barcode
Next bitmap
End Sub
End Class
End Namespace
Further Reading: How to Read Barcodes From System.Drawing Objects