Home > .NET Barcode Reader & Scanner > Best Linear & 2D Barcodes Reader & Decoder for C#, .NET Applications

How to Read Barcodes using C# Barcode Reader?

Using free C# code to scan, recognize linear & 2d barcode images in ASP.NET, Windows Forms, WPF, web and desktop applications


  • Complied advanced barcode reading & scanning functions into a mature .NET Barcode Reader Library DLL
  • Effectively run and intalled into Visual Studio .NET 8, .NET 7, 6, 5, .NET Core 3.x, 2.x, & .NET Framework 4.x, 3.x, 2.x
  • Scan and decode common linear & 2d barcode images in VS C#.NET, ASP.NET web form projects
  • Support barcode image recognition in several file formats, such as Jpg, Gif, Png, Bmp, Tiff
  • Use free Visual C# code to scan maximum one barcode per image, page in tiff or pdf document
  • Use free Visual C# code to read partial 1d or 2d barcode image instead of the whole file
  • Mainly decode and read C# Code 39, C# Code 128, C# EAN-13, C# QR-Code, C# Data Matrix, C# PDF-417, ect

C# Barcode Reader Library

QR Code, Data Matrix, Code 128, GS1, EAN/UPC. Multi-thread reading in C# ASP.NET, Windows application.

Download Now
NuGet Ready
.NET 5+
.NET Framework 4.x, 3.x, 2.x

Overview

BarcodeLib.com C# Barcode Reader for .NET is a .NET barcode reader component that can recognize linear and 2D barcode images. It can be used in:
  • ASP.NET Website Appliations
  • .NET Windows Forms Appliations
  • .NET, C#, VB.NET Class Library Applications
  • .NET Console Applications
Attention, the first character of barcode data read by the trial package will be a random character.


Install Barcode Reader Library

You can download and install our barcode reader library by using our NuGet packages or by downloading the free trial package from this site.

From NuGet

BarcodeLib C# Barcode Reader library has published several NuGet packages for your various .net development projects. You can install them through the NuGet Package Manager in Visual Studio .NET.

  • BarcodeLib.BarcodeReader.Common : The barcode reader library is built by .NET Standard 2.0. It works for .NET 8, .NET 7, 6, 5, .NET Core 3.1, 2.1, and .NET Framework 4.8. It depends on System.Drawing.Common on Windows system only. Visit it from nuget.org

  • BarcodeLib.BarcodeReader.SkiaSharp : This barcode scanner library is a modified version of BarcodeLib.BarcodeReader.Common. It is using SkiaSharp package instead of System.Drawing.Common. It works for non-Windows systems, such as Linux, MacOS. Visit it from nuget.org

  • BarcodeLib.Barcode.Reader.NET.Framework : This C# barcode reader library is for .NET Framework 4.x, 3.x and 2.x. It supports barcode recognition in C# ASP.NET (.net framework), MVC, WinForms, WPF projects. Visit it from nuget.org

Download from Site

BarcodeLib C# Barcode Reader library is free to download. You can click the following link to download the trial package:
Download C# barcode reader SDK free trial package

Install barcode library DLL to .NET projects


Install on .NET Core apps on Windows Operating System
  • For .NET Core app, add BarcodeLib.BarcodeReader.Common.dll from the downloaded package"/DLL/NET-Standard/" to the .NET project reference.
  • Search and install NuGet package System.Drawing.Common from NuGet Package Manager.

Install on .NET Core apps on Linux, MacOS... (non-Windows Operating System)
  • For .NET Core app, add BarcodeLib.BarcodeReader.SkiaSharp.dll from the downloaded package"/DLL/NET-Standard/" to the .NET project reference.
  • Search and install NuGet package SkiaSharp from NuGet Package Manager.

Install on .NET Framework applications
  • For .NET Framework 4.x application, add BarcodeLib.BarcodeReader.dll from download pacakge "/DLL/NET40/" to the .NET project reference.
  • For .NET Framework 3.x or 2.x application, add BarcodeLib.BarcodeReader.dll from download pacakge "/DLL/NET20/" to the .NET project reference.


How to scan, read barcodes in C#

Read barcode from image is a simple task. We will take Code 128 barcodes recognition as examples.
  1. Create a OptimizeSetting object with scanning barcode type(s) specified.
  2. Call method BarcodeReader.ReadBarcode() to read, scan barcodes from an image file path, image object in Stream object or binary data.
OptimizeSetting options = new OptimizeSetting(BarcodeReader.CODE128);
BarCode[] datas = BarcodeReader.ReadBarcode("barcode-sample.png", options);
foreach (BarCode aBarcode in datas)
{
    String data = aBarcode.GetMessage();
}



Scan barcode image with multiple barcode types

OptimizeSetting options = new OptimizeSetting(
    new int[] {
        BarcodeReader.CODE128,
        BarcodeReader.EAN13,
        BarcodeReader.UPCA,
        BarcodeReader.QRCODE});
BarCode[] datas = BarcodeReader.ReadBarcode("multiple-barcode-types-sample.png", options);
foreach (BarCode aBarcode in datas)
{
    String asciiText = aBarcode.GetMessage();
}



Advanced barcode scanning options using C#


How to quickly scan and recognize a barcode in C#?


If you need to scan a large size image file, like 4mb per image, and there is only one barcode inside the image file, you can improve the barcode reading speed by the following option applied.
  • When the MaxOneBarcodePerPage option is true, once the barcode reader library recognizes a barcode, it will immediately stop scanning the remaining image areas.
OptimizeSetting setting = new OptimizeSetting(BarcodeReader.CODE128);
setting.setMaxOneBarcodePerPage(true);


How to scan, read barcodes from specified regions in image?

In addition to full‑image scanning, the library offers partial‑area scanning to increase reading speed.

The C# source code below explains how to scan top 20% and bottom 20% of the image area during barcode scanning. It will reduce lots of image scanning time, CPU and memory usage.

To define the scanning region, just provide the top‑left and bottom‑right anchor points. Each coordinate is a percentage of the image's total width and height. Thus (0%, 0%) marks the top‑left corner, while (100%, 100%) marks the bottom‑right corner of the whole image.

OptimizeSetting setting = new OptimizeSetting(BarcodeReader.CODE128);

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);
BarCode[] datas = BarcodeReader.ReadBarcode("barcode-sample.png", setting);
foreach (BarCode aBarcode in datas)
{
    String data = aBarcode.GetMessage();
}


How to scan, read barcodes from specified directions in image?

The C# barcode library allows you to direct barcode scanning along specific axes. This behavior is configured within the OptimizeSetting class by setting the setReadDirectionOrder() method. You can choose one direction or multiple directions to scan the barcode image. The enumeration provides the following directional modes:
  • BarcodeReader.DIRECTION_LEFT_TO_RIGHT. Scan the image from the left side toward the right.
  • BarcodeReader.DIRECTION_TOP_TO_BOTTOM. Scan the image from the top downward.
  • BarcodeReader.DIRECTION_RIGHT_TO_LEFT. Scan the image from the right side toward the left.
  • BarcodeReader.DIRECTION_BOTTOM_TO_TOP. Scan the image from the bottom upward.
The following C# code sample demonstrates how to read a Code 128 barcode image using all four scanning directions.

OptimizeSetting setting = new OptimizeSetting(BarcodeReader.CODE128);
setting.setReadDirectionOrder(new int[] {
    BarcodeReader.DIRECTION_LEFT_TO_RIGHT,
    BarcodeReader.DIRECTION_RIGHT_TO_LEFT,
    BarcodeReader.DIRECTION_TOP_TO_BOTTOM,
    BarcodeReader.DIRECTION_BOTTOM_TO_TOP
});
BarCode[] datas = BarcodeReader.ReadBarcode("barcode-sample.png", setting);
foreach (BarCode aBarcode in datas)
{
    String data = aBarcode.GetMessage();
}
Note: By default, the barcode reader library will scan a barcode image using all four scanning directions.


Apply barcode image sampling step in C#

When the C# barcode reader library processes a raster image file, it scans the pixel data row by row. You can control the scanning granularity by adjusting the ReadOncePerRowsCount property found in the OptimizeSetting class.
  • Call method setReadOncePerRowsCount(). Define the scanning step size, i.e., how many lines are advanced between each scanned line.
    The minimum value is 1, which means every line is scanned.
    The default value is 5 (scanning one line out of every five).
Next, we'll take the C# sample code provided above and update the scan options with the following code snippet.

setting.setReadOncePerRowsCount(5);


Improve barcode recognition ratio by zooming the image

Sometimes zooming a barcode image will improve barcode recognition rates, because it provides the barcode decoder with a more detailed and information‑rich image, transforming a blurry or indistinct barcode into data that the algorithm can reliably interpret.

The following C# demo codes explain how to apply image zooming using C# Barcode Scanner library. Here we will try to zoom the image to 150% of its original size.

OptimizeSetting setting = new OptimizeSetting(BarcodeReader.CODE128);
setting.setResizeRatio(1.5f);


Parse Scanned Barcode Data Text in C#

Parse ASCII characters

ASCII table includes 128 characters. 95 printable characters and 33 control characters (non-printing chars). ASCII control characters range from 0x00 to 0x1F, plus 0x7F. They have no visible printable symbols. Direct output causes garbled text, requiring dedicated methods to convert them into visual markers.

The following Barcode Formats ASCII characters encoding and decoding.
  • QR Code
  • Data Matrix
  • PDF417
  • Code 128
  • Code 39 (extension mode only)
BarcodeLib C# Barcode Reader library provides methods to visualize ASCII control characters.
  • Call method GetMessageInASCII to print barcode encoding ASCII control characters using library pre-defined labels.
OptimizeSetting options = new OptimizeSetting(
    new int[] { 
        BarcodeReader.CODE39EX, 
        BarcodeReader.CODE128});
BarCode[] datas = BarcodeReader.ReadBarcode("code128-39-barcodes-sample.png", options);
foreach (BarCode aBarcode in datas)
{
    String asciiText = aBarcode.GetMessageInASCII();
}
The following image contains two barcodes (Code 128, and Code 39 extension). Both of them are encoding one ASCII control character carriage return. The barcode reader library will decode the barcode text string and print the control char using pre-defined label [CR] in C# program.


Process GS1 data elements

The GS1 data message is a group of GS1 system element strings. An element string is the combination of a GS1 Application Identifier (AI) and its data field.

Here is a standard GS1 data element string, "(01)99012345678900(400)PO20240516-123(10)ABC123(11)240516".

The following barcode formats support GS1 data encoding:
GS1-128, EAN-13, EAN-8, UPC-A, UPC-E, GS1 QR Code, GS1 Data Matrix, ITF-14.

A sample GS1 Data Matrix barcode image


The C# source code below explains how to read GS1 data elements from the GS1 barcode image using C# barcode reader library.
  • In the scanned barcode information BarCode object, use property IsGS1Compitable to indentity whether it is a GS1 barcode or normal ISO barcode.
    This property is working for: Code 128 (GS1-128), Data Matrix, and QR Code.
OptimizeSetting options = new OptimizeSetting(
    new int[] {
        BarcodeReader.DATAMATRIX,
        BarcodeReader.QRCODE,
        BarcodeReader.CODE128});
BarCode[] datas = BarcodeReader.ReadBarcode("gs1-barcodes-sample.png", options);
foreach (BarCode aBarcode in datas)
{
    if (aBarcode.IsGS1Compitable)
    {
        string gs1Text = aBarcode.GetMessage();
    }
}



View more information about GS1 barcode reader : How to scan, read GS1 barcodes using C# barcode reader library?


Process multiple barcode data in Structured Append mode

Every barcode symbology has maximum number of data to encode. To encode large data message, some barcode symboloy support Structured Append mode.

QR Code and Data Matrix do support encode data with Structured Append mode. You can encode up to 16 QR Code or Data Matrix barcodes to store one data message.

View more information here : How to read barcodes with Structured Append data mode using C#?


Process Unicode text

All of 2D (matrix) barcode symbologies do not support encoding Unicode text directly into barcodes. However most of 2d barcode specifications do support byte array data encoding.

BarcodeLib Barcode Reader for C# library allows you to use one line of code to read, decode Unicode text from 2d barcodes, such as QR Code, Data Matrix and PDF417.

  • Call method GetMessage to decode Unicode text string from 2d barcodes directly.
OptimizeSetting options = new OptimizeSetting(
    new int[] {
        BarcodeReader.DATAMATRIX,
        BarcodeReader.QRCODE,
        BarcodeReader.PDF417});
BarCode[] datas = BarcodeReader.ReadBarcode("2d-barcodes-unicode-text-sample.png", options);
foreach (BarCode aBarcode in datas)
{
    string barcodeUnicodeText = aBarcode.GetMessage();
}



You can view the details here : How to read, parse 2d barcodes with Unicode text using C# barcode reader library?


If you need C# barcode generating details, please see:





.NET Barcode Reader, ASP.NET Barcode Reader, C#.NET Barcode Reader, VB.NET Barcode Reader, QR Code .NET Reader, QR Code ASP.NET Reader, QR Code C# Reader, QR Code VB.NET Reader, Data Matrix .NET Reader, Code 128 .NET Reader,Code 39 .NET Reader. .NET Barcode Generator Control, ASP.NET Barcode Generator Control.