C# Barcode Reader & Scanner SDK Tutorial

How to scan, read linear, 2d barcode images in C#.NET application

Reading & Scanning Linear, 2D Barcode Images in Visual C# .NET using C#.NET Barcode Reader

In this C# tutorial, you will learn how to scan an image and read barcode data from it in your C# ASP.NET web app and Windows application.

  • Scan the whole image or partial of the image area
  • Support multiple image formats, such as bitmap, jpg, png, gif, TIFF
  • Auto detect barcodes with any rotation angles
  • Support more than 20 barcode types
  • Read barcode data with located area information

How to scan, read barcodes from image using C#

  1. Download .NET Barcode Reader Library
  2. Install C# library to read barcode from images in .NET apps
  3. Step by Step Tutorial

OnBarcode .NET Barcode Reader is a C#.NET component (dll) which reads and scans barcode images in Visual C# .NET applications.
.NET Barcode Reader is 100% built on C# 2005, for reading & scanning Code 39, Code 128, GS1-128/EAN-128, Interleaved 2 of 5, UPC-A, UPC-E, EAN-8, EAN-13, and PDF-417 barcodes.


For .NET (7, 6, 5), and .NET Core on Windows

  • Add .net dll OnBarcode.Barcode.BarcodeScanner.dll from {Download package}/dll/NetStandard2.0/ to your .net project
  • Add NuGet Package System.Drawing.Common from NuGet Package Manager to your .net project

For .NET (7, 6, 5), and .NET Core on non-Winodws, such as Linux

  • Add .net dll OnBarcode.Barcode.BarcodeScanner.Skia from {Download package}/dll/NetStandard2.0/ to your .net project
  • Add NuGet Package SkiaSharp from NuGet Package Manager to your .net project

For .NET Framework 4.x, 3.x 2.x

  • Add .net dll OnBarcode.Barcode.BarcodeScanner.dll from {Download package}/dll/net40/ or /net20/ to your C# project reference

About trial version dll vs licensed dll

When you have downloaded and installed the free trial version of OnBarcode .NET Barcode Generator SDK, you will get all almost exactly same features as the licensed dll.

There is only one limit in the trial version of dll. The first character or digit from returned barcode data is randomly generated. In the licensed sdk, we have removed the limit.

Quick to start using C# barcode reader library

1. How to scan & read linear, 2D barcodes in C# class?

   string[] barcodes = BarcodeScanner.Scan("code128-image.gif", BarcodeType.Code128); 

2. To improve the reading speed, call ScanSingleBarcode, if there is maximum one barcode per image.

   string[] barcodes = BarcodeScanner.ScanSingleBarcode("code39-image.gif", BarcodeType.Code39); 

3. To scan defined areas in the image in C#

   List<SRegion> areas = new List<SRegion>();
SRegion area = new SRegion(0, 0, 50, 60);

string[] barcodes = BarcodeScanner.ScanRegions("code39image.gif", BarcodeType.Code39, areas);

About class BarcodeDetail in C#

You can quickly get the scanned barcode data in string using the above methods. Sometimes you need scan and find the barcode location on the image file or read special data from barcodes, such as GS1 data message, barcode data in Structure Append mode.

We have provided the C# class BarcodeDetail to help get more information about the scanned barcode data. In class BarcodeDetail, we have provided useful properties and methods for each scanned barcodes.

  • Rotation: find the rotation angle about the scanned barcode.

  • X1, Y1, X2, Y2, X3, Y3, X4, Y4: 8 properties which define the scanned barcode location on the image file.

  • IsStructuredAppend: It is for QR Code and Data Matrix barcodes only. To identify whether the QR Code or Data Matrix barcode is in Structure Append mode. If so, you need combine the scanned barcode data with other barcodes from the same message. You can view the details here:
    How to read barcode data in Structure Append mode in C#.net?

  • IsGS1Compitable: It is for QR Code, Data Matrix and Code 128 barcodes only. To identify whether the found barcode is GS1 compatible. Know more information, view here:
    How to read GS1 barcode data using C#?

  • Method isMacroPDF417(): It is for PDF417 barcodes only. View more information about Macro PDF417 barcode reading in C#:
    How to read Macro PDF417 barcodes using C#?

  • Method GetDataBytes(). You can get the read barcode data in byte array.

  • Method GetMessage(), GetMessage(Encoding enc). You can get the scanned barcode data using default UTF8 encoding or your specified encoding format.

To scan and get more information about the barcode in C#

   BarcodeDetail[] barcodeDetails = BarcodeScanner.ScanInDetails("code39image.gif", BarcodeType.Code39);

Read mutliple barcodes

How to read multiple barcode types from a single image file?

Scan and find every barcode types from the image file

You could use the property BarcodeType.All to scan and find all supported barcodes from a single image file. Here is the C# sample code:
BarcodeDetail[] datas = BarcodeScanner.ScanInDetails(inputFilePath, BarcodeType.All);

Scan and find all barcodes with specified types from the image file

Using C# barcode reader, you can provide a list of target barcode types, and find all barcodes from these types inside an image file. Below is the C# sample code to read all barcodes, which are QR Code or Code 128.
            BarcodeDetail[] datas = BarcodeScanner.ScanInDetails(inputFilePath, 
                new List<BarcodeType> {BarcodeType.QRCode, BarcodeType.Code128});

Multi-thread in barcode scanning

To improve the barcode scanning process speed, OnBarcode C# barcode reader library does support scanning multiple image files in multiple threads.

The C# sample source code shows how to scanning barcodes from mutliple image files in multi-thread programming.

String[] inputFilePaths = new String[] {
    Path.Combine(inputFolder, "1.png"),
    Path.Combine(inputFolder, "2.png"),
    Path.Combine(inputFolder, "3.png")
String[] result = scanFilesWithMultiThread(inputFilePaths, BarcodeType.Code128);
Console.WriteLine("Count: {0}", result.Length);
foreach (String s in result)
    Console.WriteLine("Message: {0}", s);

private static String[] scanFilesWithMultiThread(String[] inputFilePaths, BarcodeType type)
    if (inputFilePaths == null || inputFilePaths.Length == 0)
        return new String[0];
        //  Scan each file in a Task.
        System.Threading.Tasks.Task<String[]>[] tasks = new System.Threading.Tasks.Task<String[]>[inputFilePaths.Length];
        for (int i = 0; i < inputFilePaths.Length; i++)
            tasks[i] = new System.Threading.Tasks.Task<String[]>(
                (args) => scanSingleFile((Object[])args), new Object[2] { inputFilePaths[i], type }
        //  Wait for all Tasks done.

        //  Combine all scan results.
        List<String> result = new List<String>();
        foreach (System.Threading.Tasks.Task<String[]> task in tasks)
        return result.ToArray();
    catch (Exception)
        return new String[0];

public static String[] scanSingleFile(Object[] args)
        return BarcodeScanner.Scan((String)args[0], (BarcodeType)args[1]);
    catch (Exception)
        return new String[0];

Read barcodes from imperfect images

Barcodes are compatible with ISO standards
You'd better use ISO standards fully compatible barcode generator to create barcodes. For example, ISO / IEC 18004 specifies that all valid QR Codes should have at least 10X margins (X is the QR module size).

Scan one barcode type at one time
Though Barcode reader sdk supports scanning multiple barcode types at one time, we still strongly recommend you to read, scan one barcode type at one time. Use multiple barcode types may lower the scan recognition ratio. For example, Code 39 and Code 128 are both linear barcodes. If you scan both barcode types at one time, and the scanned barcode image file is imperfect, you may get the wrong results.

Try to scan barcodes from specified regions of the image file
Some imperfect images may contain noises covered all area of the image. To get the scan result successflly, scan certain areas of the image is a useful method. View detailed C# code here:
How to scanned target areas in the image using C#

C# Barcode Reading & Scanning Tutorials

Barcode Reader SDK for C#.NET - Barcode Image Reading

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.