In this tutorial, developers will learn how to scan and read QR Code barcode data from images in C# and VB.NET ASP.NET web applications, as well as in Windows Forms and WPF desktop applications.
C# QR Code Reader Library
QR Code, Data Matrix, Code 128, GS1, EAN/UPC. Multi-thread reading in C# ASP.NET, Windows application.
The QR Code reader functionality is part of the C# Barcode Reader component, which enables scanning and decoding of QR Code barcodes from image files. This component is designed for easy integration into C# and VB.NET projects, supporting a wide range of .NET platforms including ASP.NET Core, ASP.NET Framework, WinForms, and WPF. The library provides comprehensive scanning capabilities, including support for multiple image formats, region specific scanning, and detailed barcode property extraction.
Download & Install
You can download and install the nuget package BarcodeLib.BarcodeReader in the Visual Studio IDE.
You can also download the free trial package from our site here Download Free Trial Package.
And add downloaded BarcodeLib.BarcodeReader.dll to your .NET project reference.
How to scan, read QR Code from images using C#?
Scan and read QR-Code barcode in C# is an easy and simple task. The following C# source will scan and read QR Code data from image file in C# application.
Scanning and Reading All QR Code Information from an Image File Using C#
The ScanInDetails() method returns detailed information about each scanned QR Code in BarcodeDetail objects.
Key properties of BarcodeDetail include:
TypeID: Check the scanned it is a QR Code, it will return the int value 9
GetTypeName(): If it is a QR Code, it will return string QRCODE
Corners: Four coordinate points (PointF) defining the detected QR Code region.
IsGS1Compitable: Indicates whether the QR Code is GS1 compatible.
GetDataBytes(): Retrieves the QR Code data as a byte array.
GetMessage(): Retrieves the QR Code data as a formatted string.
getImageFileIndex(): If scanning QR Code from multiple frame images, such as TIFF, GIF, it will return the scanned QR Code located image frame index. The first image frame is 0.
getImageFilePath(): Return the scanned image file path. Return "", if the scanned image is in memory.
Extracting QR Code Barcode Properties
After obtaining a BarcodeDetail object, call getBarcodeExtraInfos() to retrieve QR Code specific properties:
ECL: Error correction level.
Encoding: Encoding data mode; QRCodeEncoding.Auto indicates multiple modes combined.
Version: QR Code version used during encoding.
hasStructuredAppend: Whether the symbol is in Structured Append mode.
Count: Total number of symbols in the Structured Append group.
Index: Index position of the symbol within the Structured Append group (starting from 1).
The library simplifies scanning GS1 QR Codes and parsing GS1 data messages. The IsGS1Compitable property indicates GS1 compliance, and GetMessage() returns a formatted string with parentheses delimited AI codes.
OptimizeSettingoptions=newOptimizeSetting(BarcodeReader.QRCODE);
BarCode[] datas=BarcodeReader.ReadBarcode("qrcode-sample.png", options);
foreach (BarCodedataindatas)
{
// Verify whether it is a GS1 QR Codeif (data.IsGS1Compitable)
{
// Get message in string format.// Eg. "(415)5412345678908(3911)710125"Stringmsg=data.GetMessage();
Debug.WriteLine("Raw Data: '{0}'", data.Data);
Debug.WriteLine("Text Message: {0}", msg);
// Retrieve each AI and its data from the message.// Eg.// AI: 415// Data: 5412345678908// AI: 3911// Data: 710125String[] vals=msg.Split(newchar[] { '(', ')' },
StringSplitOptions.RemoveEmptyEntries);
for (inti=0; i<vals.Length; i+=2)
{
Debug.WriteLine("AI: {0}", vals[i]);
Debug.WriteLine("Data: {0}", vals[i+1]);
}
}
}
Advanced QR Code Image Scanning Features Using C#
The library provides several methods to improve scanning speed and flexibility.
Scan a Single QR Code
When the image contains only one QR Code, set setMaxOneBarcodePerPage() in OptimizeSetting to improve performance by stopping after the first detection.
Set setMaxOneBarcodePerPage() to true, if there is maximum one barcode per image or per page in tiff or pdf document.
If setMaxOneBarcodePerPage() is true, the C# barcode reader library will stop scanning the barcode immediately, once detects one barcode.
If setMaxOneBarcodePerPage() is false (default value), the library will use total 5 algorithms and each will scan the whole image from 4 directions.
Scan the partial image instead of the whole file.
If the barcode is always located one specified area in the image, you can set and let the library scan that area only. And it will reduce lots of scanning time, CPU and memory usage.
You just specify the left top point and right bottom point of the area (the point X, Y values are expressed in percentage of the whole image, so image most left top point is (0%, 0%), and most right bottom point is (100%, 100%)).
You can specify multiple areas to scan the QR Code inside one image file.
This tutorial has provided a comprehensive guide to integrating QR Code reading capabilities into .NET applications using C# and VB.NET. Developers can leverage the BarcodeLib Barcode Reader SDK to scan and decode QR Code symbols from image files, extract detailed barcode properties, and process various data formats including ASCII, Unicode, binary, and GS1 structured messages. The component seamlessly integrates into ASP.NET Core, ASP.NET Framework, WinForms, and WPF applications, enabling robust QR Code reading functionality across multiple .NET environments.