How to read, scan QR Code in C# ASP.NET, MVC web app?

Online tutorial for reading & scanning QR Code barcode images in C# ASP.NET, MVC, WinForms, WPF application

How to read, scan, decode QR Code images in C#.NET class, ASP.NET Web & Windows applications



In this C# tutorial page, you will learn how to scan, read QR Code barcode data from images in C# ASP.NET web app and Windows application.

  • Scan standard QR Code and GS1 QR Code
  • Easy to read text with various encoding from QR Code image
  • Read multiple raster image formats, TIFF, bitmap, jpeg, gif, png.
  • Scan the whole image area or partial of it.
  • Extract QR Code data value with barcode location information
  • Build-in API to easily parse ASCII text, Unicode, Binary data, and GS1 data elements
  • Quick to build QR Code scanning feature in ASP.NET Core, MVC, ASP.NET Framework, WinForms, WPF web and desktop applications
  • Support .NET 9, 8, 7, 6, 5, .NET Core 3.1, 2.1, .NET Framework 4.x, 3.x, 2.x

How to read, scan QR Code image in C# application

  1. Download .NET QR Code Reader Library
  2. Install C# library to scan barcode images in .NET apps
  3. Step by Step Tutorial












  • Scan QR Code barcode in C# class, Console applications
  • Read QR Code barcode in C# ASP.NET Core web app
  • Read, decode QR Code images in Visual Studio C# windows application
  • Easy and simple to integrate QR Code reader component (single dll file) into your C# project
  • Support .NET 9, 8, 7, 6, 5, .NET Core 3.1, 2.1, .NET Framework 4.x, 3.x, 2.x
  • Scanning, decoding QR Code from multiple image formats, like BMP, GIF, JPEG, PNG, TIFF formats
  • Scanning, reading QR Code from multi-page TIFF documents




Quick to Read QR Code using C#

Top
You can quickly scan qrcodes from an image file in your C# program using C# barcode reader library.
  • Call method BarcodeScanner.Scan() with QR Code image file path, and scanned barcode format BarcodeType.QRCode, you will get all QR Codes data messages inside the image file
            string[] datas = BarcodeScanner.Scan("qrcode-sample.png", BarcodeType.QRCode);

You can also use method BarcodeScanner.ScanInDetails() to scan and read all information about QR Codes inside the image. View details here How to scan, read QR Code location information using C#?




Scan and read all QR Code informations from an image file using C#

Top
Call method BarcodeScanner.ScanInDetails() with the same input parameters, you will get all scanned QR Codes with detailed information in BarcodeDetail objects, such as scanned QR Code region.

BarcodeDetail[] datasInDetail = BarcodeScanner.ScanInDetails("qrcode-sample.png", BarcodeType.QRCode);

Here are some information about BarcodeDetail
  • Rotation: get the scanned QR Code rotation angle
  • X1, Y1, X2, Y2, X3, Y3, X4, Y4: 4 coordinate locations on the scanned image to cover the scanned QR Code symbol
  • IsGS1Compitable: If true, the scanned QR Code is a GS1 compatible QR Code. You need read the GS1 data message from it.
  • IsStructuredAppend: If true, the scanned QR Code symbol is part of the Structured Append QR Code symbols
  • GetDataBytes(): Get the QR Code data in byte array.
  • GetMessage(): Get the QR Code data in specified encoding format.
For more information about class BarcodeDetail go here: About class BarcodeDetail in C#




Process scanned QR Code data message using C#

Top
QR Code supports encoding lots of character sets and some industry standard data formats. To help process these complex data message, barcode reader library develops multiple methods to handle them.

Here you will learn how to process the following character sets or data message from scanned QR Code in C#
  • ASCII text. Including printing and non-printing chars.
  • Unicode text
  • Binary data
  • GS1 data elements


ASCII text characters

ASCII text include 128 characters. The first 32 characters and the last character are non-printing ones, such as character 'carriage return'.

The following C# source code shows how to scan QR Code and parse the scanned ASCII characters using C#.
  • Use method BarcodeScanner.Scan() to scan the image containing QR Code symbols.
  • Parse the scanned QR Code data and replace non-printing char 'carriage return' in the example with visible label '[CR]'
            String[] result = BarcodeScanner.Scan("C://Input//qrcode-ascii-sample.png", BarcodeType.QRCode);

            if (result.Length > 0)
            {
                foreach (String msg in result)
                {
                    Debug.WriteLine("QR Code Raw Message: '" + msg + "'");
                    String tmp = msg.Replace("\r", "[CR]");
                    Debug.WriteLine("QR Code ASCII Text: '" + tmp + "'");
                }
            }
            else
            {
                Debug.WriteLine("No QR Code Scanned!");
            }


Unicode text

QR Code supports Unicode text encoding. To encode Unicode characters into QR Code, the barcode software usually will convert Unicode text to binary data, and create QR Code with binary data using QR Code binary data mode.

To decode QR Code with Unicode text properly, you need use the same encoding as the QR Code generator. The most common encoding is using UTF8 encoding.

The C# code below explains how to read QR Code and decode Unicode text using UTF8 (System.Text.Encoding.UTF8) encoding in C# application.
            BarcodeDetail[] datas = BarcodeScanner.ScanInDetails(
                "C://Input//qrcode-unicode.png", BarcodeType.QRCode);
            
            for (int j = 0; j < datas.Length; j++)
            {
                string textMsgDecoded = System.Text.Encoding.UTF8.GetString(
                    datas[j].GetDataBytes());

                Console.WriteLine("Unicode text: " + textMsgDecoded);
            }


GS1 data message

The GS1 System uses QR Code as one of its data carrier. The GS1 data message encoded in QR Code usually includes a list of AI (Application Identifier) Code and AI data pair, and some control characters, such as Function 1 Symbol Character (FNC1).

The OnBarcode Barcode Reader library will help you easily scan GS1 QR Code and parse GS1 data message without knowing any GS1 control characters. You can easily get the list of GS1 data elements.
    BarcodeDetail[] result = BarcodeScanner.ScanInDetails("C://Input//qrcode-gs1-data.png", BarcodeType.QRCode);

    foreach (BarcodeDetail b in result)
    {
        //  Indicate if the QR Code is conform to GS1 system.
        if (b.IsGS1Compitable)
        {
            //  Get message in string format.
            //  Eg. "(415)5412345678908(3911)710125"
            String msg = b.GetMessage();
            Console.WriteLine("Raw Data: '{0}'", b.Data);
            Console.WriteLine("Text Message: {0}", msg);
            //  Retrieve each AI and its data from the message.
            //  Eg.
            //  AI:   415
            //  Data: 5412345678908
            //  AI:   3911
            //  Data: 710125
            String[] vals = msg.Split(new char[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < vals.Length; i += 2)
            {
                Console.WriteLine("AI:    {0}", vals[i]);
                Console.WriteLine("Data:  {0}", vals[i + 1]);
            }
        }
    }




Advanced QR Code Image Scanning Features using C#

Top
OnBarcode Barcode Reader library provides several methods to improve the QR Code scanning speed.
  • Quick to scan a single QR Code. If this feature is enabled, once the barcode library scan and detect a QR Code on the fil, it will stop run the remaining job.
  • Scan QR Code and other barcode format at once
  • Scan QR Codes from specified regions in the image file


Scan a single QR Code

If this feature is enabled, once the barcode library scan and detect a QR Code on the fil, it will stop run the remaining job.

This feature will really improve the reading speed, if the scanning file contains only one QR Code symbol.
string[] barcodes = BarcodeScanner.ScanSingleBarcode("qrcode-single-barcode.png", BarcodeType.QRCode);


Scan multiple QR Codes

You can easily scan QR Code and other barcode formats (such as Code 128, EAN/UPC) from an image file at once. Or you can scanned all barcode reader library supported barcode formats (using property BarcodeType.All) from a file.
BarcodeDetail[] datas = BarcodeScanner.ScanInDetails("qrcode-multiple-formats.png",
    new List<BarcodeType> { BarcodeType.QRCode, BarcodeType.Code128 });


BarcodeDetail[] datasInDetail = BarcodeScanner.ScanInDetails("qrcode-all-formats.png", BarcodeType.All);


Scan image regions to read QR Codes

To improve the reading speed and reduce the reading error, you can define regions inside the image file. The barcode reader library will scan the QR Code from the specified regions, and it will help to improve the QR Code and other barcodes reading performance.
List<SRegion> regions = new List<SRegion>();
regions.Add(new SRegion(0, 0, 50, 60));
regions.Add(new SRegion(100, 100, 50, 60));

string[] barcodes = BarcodeScanner.ScanRegions("qrcode-barcodes.png", BarcodeType.QRCode, regions);


List<SRegion> regions = new List<SRegion>();
regions.Add(new SRegion(0, 0, 50, 60));
regions.Add(new SRegion(100, 100, 50, 60));

string[] barcodes = BarcodeScanner.ScanSingleBarcodeRegions("qrcode-barcodes.png", BarcodeType.QRCode, regions);
















OnBarcode is a market-leading provider of barcode imaging generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.