C# Barcode Reader How-Tos
PM > Install-Package BarcodeLib.BarcodeReader


In this article
Home > .NET Barcode Reader > .NET Barcode Reading Guide > .NET QR-Code Barcode Reader for C#, VB.NET Applications

How to Read and Scan QR Code in C# ASP.NET and MVC Applications

Scan & Read QR-Code barcodes in C#.NET, VB.NET, ASP.NET projects
  • Easily read & scan QR-Code barcodes in .NET applications
  • Quickly scan & decode QR Code 2d barcodes from specified area inside the image document
  • Decoding & reading QR Code barcode images in JPEG, GIF, PNG, BMP, TIFF file formats
  • 100% build in C#.NET, complying with .NET 2.0 and later versions
  • Complete sample C#.net, VB.net sample codes for Visual C# & VB.NET developers
  • Mature & reliable QR Code .NET Barcode Reader Component since 2003
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.

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.
Install .NET QR Code Barcode Reader & Scanner
  1. Add BarcodeLib.BarcodeReader.dll to your .NET project reference.




Scan & Read QR-Code Barcodes in C#.NET
Scan and read QR-Code barcode in C# is an easy and simple task. One line of C# code finishes the job.
     string[] results = BarcodeReader.read("c:/qrcode-barcode.gif", BarcodeReader.QRCODE);
The above C# code will get all QR-Code barcodes in image file "qrcode-barcode.gif".
Scan & Read QR-Code Barcodes in VB.NET
Scan and read QR-Code barcode in VB.NET is an easy and simple task. One line of vb.net code finishes the job.
     Dim datas() As String = BarcodeReader.read("c:/qrcode-barcode.gif", BarcodeReader.QRCODE)
The above VB.NET code will get all QR-Code barcodes in image file "qrcode-barcode.gif".
Optimize QR-Code Barcode Reading Performance in C#.NET & VB.NET
You can customize our .NET barcode reader component, to improve QR-Code barcode reading speed, when you are scanning large image size (like 4mb per image).
  1. Set maxOneBarcodePerPage to true, if there is maximum one barcode per image or per page in tiff or pdf document.
    If maxOneBarcodePerPage is true, the .net barcode reader library will stop scanning the barcode immediately, once detects one barcode.
    If maxOneBarcodePerPage is false (default value), the library will use total 5 algorithms and each will scan the whole image from 4 directions.

  2. 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%)).
The following C# code explains how to scan top 20% of the image and bottom 20% of the image.
     OptimizeSetting setting = new OptimizeSetting();

setting.setMaxOneBarcodePerPage(true);

ScanArea top20 = new ScanArea(new PointF(0.0F, 0.0F), new PointF(100.0F, 20.0F));

ScanArea bottom20 = new ScanArea(new PointF(0.0F, 80.0F), new PointF(100.0F, 100.0F));

List<ScanArea> areas = new List<ScanArea>();
areas.Add(top20);
areas.Add(bottom20);

setting.setAreas(areas);

string[] results = BarcodeReader.read("c:/qrcode-barcode.gif", BarcodeReader.QRCODE, setting);
The following VB.NET code explains how to scan top 20% of the image and bottom 20% of the image.
     Dim setting As OptimizeSetting = New OptimizeSetting()

setting.setMaxOneBarcodePerPage(True)

Dim top20 As ScanArea = New ScanArea(New Drawing.PointF(0.0F, 0.0F), New Drawing.PointF(100.0F, 20.0F))

Dim bottom20 As ScanArea = New ScanArea(New Drawing.PointF(0.0F, 80.0F), New Drawing.PointF(100.0F, 100.0F))

Dim areas As List(Of ScanArea) = New List(Of ScanArea)
areas.Add(top20)
areas.Add(bottom20)

setting.setAreas(areas)

Dim datas() As String = BarcodeReader.read("c:/qrcode-barcode.gif", BarcodeReader.QRCODE, setting)


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:
  • Rotation: Rotation angle of the scanned QR Code.
  • X1, Y1, X2, Y2, X3, Y3, X4, Y4: Four coordinate points defining the QR Code region.
  • IsGS1Compitable: Indicates whether the QR Code is GS1 compatible.
  • IsStructuredAppend: Indicates whether the QR Code is part of a Structured Append group.
  • GetDataBytes(): Retrieves the QR Code data as a byte array.
  • GetMessage(): Retrieves the QR Code data as a formatted string.


Extracting QR Code Barcode Properties

After obtaining a BarcodeDetail object, call GetBarcodeProps() to retrieve QR Code specific properties:
  • Version: QR Code version used during encoding.
  • DataMode: Encoding data mode; QRCodeDataMode.Mix indicates multiple modes.
  • ECL: Error correction level.
  • IsStructuredAppend: Whether the symbol is in Structured Append mode.
  • SymbolPosition: Position of the symbol within the Structured Append group (starting from 1).
  • SymbolCount: Total number of symbols in the group.
  • Parity: 8 bit parity data.


Processing Scanned QR Code Data Messages Using C#

QR Code supports multiple character sets and industry standard data formats. The library provides methods to handle these data types:
  • ASCII text (printable and non printable characters)
  • Unicode text
  • Binary data
  • GS1 data elements


ASCII Text Characters

The following code scans a QR Code and replaces the non printable carriage return character (\r) with the visible label [CR].


Unicode Text

To decode Unicode text encoded with UTF 8, retrieve the byte array and decode it.


GS1 Data Message

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.


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, using ScanSingleBarcode() improves performance by stopping after the first detection.


Scan Multiple QR Codes and Other Barcode Formats

Multiple barcode types can be scanned simultaneously.


Scan Image Regions to Read QR Codes

Defining specific regions can improve performance and reduce errors.

For scanning a single QR Code within specified regions, use ScanSingleBarcodeRegions.


Summary

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.

.NET Barcode Reader & Scanner Supporting Barcode Types/Symbologies
Read .NET 1D Barcodes:
Read .NET 2D Barcodes:
All Decodable Linear Barcodes: Codabar, Code 39, Code 128, Interleaved 2 of 5, EAN 8, EAN 13, UPC-A, UPC-E.

All Decodable Matrix Barcodes: Data Matrix, PDF-417, QR-Code.