How to read GS1 data from barcode images in C#?

How to scan, read, parse GS1 data elements from barcode images for ASP.NET Core web app and Windows application?

Using Free C# Souce Code to Generate GS1 Barcode Labels for ASP.NET Web Application & Windows Applications



The following guide will help you how to read GS1 data message from GS1 supported barcode using C#. Parse the extracted GS1 data message with control characters into list of GS1 Application Identifier (AI Code) and a GS1 Application Identifier data field.

After this tutorial, you will be albe to
  • Scan, read GS1 data elements from barcode image directly using C#
  • Extract the GS1 data with special characters from barcode in C#
  • Support .NET 7, 6, 5 and .NET Core 3.1, 2.1 ASP.NET Core, WinForms, WPF .NET Windows application

How to read, parse GS1 data elements from barcode images using C#?

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








About GS1 data message

Top
A GS1 data message contains a group data elements. Each element string is the combination of a GS1 Application Identifier (AI Code) and a GS1 Application Identifier data field (AI Data). The AI Code is a two to four digits number.

The GS1 data message could be encoded in independent of data carrier, such as barcode, RFID (radio frequency identification), and business message.

A GS1 barcode contains a group of data elements with several special characters (such as FNC1)

The GS1 barcode complete data includes list pairs of AI code and data, and some control characters, such as "FNC1". The FNC1 is a non-printable control character used to delimit GS1 element strings of variable length.

Here is the demo ASP.NET Core web application which will scan and decode a GS1-128 barcode in the web browser.





How to read GS1 data from barcodes using C#

Top


In the following C# example, we will use a sample GS1 data "(01)09012345678901(17)240915(10)abc123(3930)978112". The sample GS1 data includes FOUR elements with four application identifier (AI Code): "01", "17", "10", "3930".

  • 01 - GTIN (identification of a trade item). The AI Code will be followed by 14 digits

  • 17 - Expiration date. The AI Code will be followed by 6 digits. the example here is Sep 15, 2024

  • 10 - BATCH/LOT: batch or lot number. The AI Code will be followed by data in variable length.

  • 3930 - Amount payable. The AI Code will be followed by 3 digits ISO currency code with applicable amount payable. The data is in variable length. The example here is Euro 112.00


We have encoded the above GS1 data into GS1-128, QR Code and Data Matrix barcodes using OnBarcode C# Barcode Generator library.

GS1-128


QR Code


Data Matrix


Now you can use our C# barcode reader library to scan, read the above barcodes. Here is the C# sample source code to read GS1-128 barcodes.

            string inputFilePath = "W://Projects//Test-Input//gs1-sample-data-gs1-128.png";
            //  Scan barcodes from the input image file.
            BarcodeDetail[] result = BarcodeScanner.ScanInDetails(inputFilePath, BarcodeType.Code128);
            foreach (BarcodeDetail b in result)
            {
                //  Indicate if the barcode is conform to GS1 specification.
                if (b.IsGS1Compitable)
                {
                    //  Get message in string format.
                    //  Eg. "(415)5412345678908(3911)710125"
                    String msg = b.GetMessage();
                    Console.WriteLine("Data: '{0}'", b.Data);
                    Console.WriteLine("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]);
                    }
                }
            }


Output in the console window:

Data: '01090123456789011724091510abc1233930978112'
Message: (01)09012345678901(17)240915(10)abc123(3930)978112
AI:    01
Data:  09012345678901
AI:    17
Data:  240915
AI:    10
Data:  abc123
AI:    3930
Data:  978112


In the data message, there are two characters are special characters (non-printable), which are defined by GS1.

In the class BarcodeDetail, we have provided a useful method GetMessage(). The message will automatically parse the scanned data message into GS1 data elements.




How to scan, read multiple GS1 barcodes from an image file using C#?

Top
Lots of the business documents (such as quotation form, invoice) will contain more than one GS1 barcodes with different barcode formats.

Here is a sample quotation form image with three GS1 barcodes printed: GS1 QR Code, GS1-128 and EAN-13.


Here we will learn how to scan and detect multiple GS1 barcodes with different barcode formats from a single image file in C# application.
  1. Call the method BarcodeScanner.ScanInDetails with the scanning barcode image file path, and the specified barcode formats: QR Code, Code 128 (GS1-128 is based on Code 128), EAN-13).
  2. For each scanned barcode information object, you can explore it's barcode format through property Type, and GS1 message using method GetMessage()
BarcodeDetail[] result = BarcodeScanner.ScanInDetails(
    "C://Input//scan-multi-gs1-barcodes-demo.png",
    new List<BarcodeType> {BarcodeType.QRCode, BarcodeType.Code128, BarcodeType.EAN13});
foreach (BarcodeDetail barcode in result)
{
    Debug.WriteLine("Barcode Type: " + barcode.Type.ToString());
    Debug.WriteLine("Message: " + barcode.GetMessage());
}


After running the barcode scanner program in Visual Studio, you will get the following results.




How to verify the scanned and decoded GS1 barcode data in C#?

Top
All scanned and decoded GS1 barcode data codes are verified by the C# Barcode Reader library. Different GS1 barcode formats will be applied with different verification algorithms.
  • GS1 QR Code, Data Matrix. The returned barcode data will be verified by Reed-Solomon error correction codewords built in the QR Code and Data Matix symbol.
  • GS1-128. The barcode data will be verified by the check character in the barcode symbol.
  • EAN/UPC. The barcode code will be verified by the check digit in the last digit of the barcode data.
  • ITF-14. The barcode code will be verified by the check digit.


Conclusion



Using OnBarcode C# barcode reader library, you do not need parse the control characters inside the GS1 barcode data message. Call barcode reader library, you can get the GS1 barcode all elements directly.












Common Asked Questions

How to setup a C# ASP.NET project to scan GS1 barcode images?

To build an ASP.NET C# web forms or MVC application to scan GS1 barcodes in web browser, you can use Visual Studio to create a new ASP.NET web project, add C# Barcode Reader library to the project reference, and quickly enable GS1 barcode image scanning function with one line of C# source code: BarcodeScanner.Scan() in the C# ASP.NET web project.

Is it possible to detect GS1 barcodes from image object directly in C# application?

Yes. Using OnBarcode C# Barcode Scanner SDK, you can scan and recognize GS1 barcode datas from image file and image data object (such as Stream, byte array) in memory in your C# ASP.NET, Windows Forms, or WPF applications.

What is a GS1 barcode?

A GS1 barcode encodes a product identification number (GTIN) that can be scanned electronically, making it easier for products to be tracked, processed, and stored. The GS1 specification has listed the following 2d and 1d barcode formats to encode GS1 data message.
  • QR Code
  • Data Matrix
  • EAN/UPC, including EAN-13, EAN-8, UPC-A, UPC-E with 2-digit or 5-digit add-on symbol.
  • GS1-128 (EAN-128 or UCC-128)
  • GS1 DataBar
  • ITF-14
Using OnBarcode C# Barcode Reader library, you are able to scan, read, decode GS1 barcodes from image files, image in memory stream object in C# ASP.NET, MVC, WinForms, WPF web and desktop applications.

What is GS1 barcode used for?

The GS1 barcodes uniquely identify your brand & products in e-commerce. GS1 standards are the most widely-used in global supply chains. C# Barcode Reader library will enable your .NET ASP.NET web and Windows projects to scan, recognize GS1 data code from image files with few lines of C# codes.

What is the difference between GS1 barcode and QR code?

The main difference between GS1 QR Code and other GS1 barcode (like the EAN/UPC, GS1-128 and ITF-14) lies in their data capacity, functionality, and use cases.
  • GS1 QR Code can encode far more characters than EAN/UPC, GS1-128 barcodes
  • GS1 QR Code also supports Reed-Solomon error corrections.
  • GS1 QR Code can be printed on a smaller size
OnBarcode provides both GS1 barcode generation and GS1 barcode scanning library for C# ASP.NET Core, MVC, blazor, Windows Forms, WPF web and desktop applications.

Does C# Barcode Reader SDK support GS1 EAN/UPC barcode with add-on data?

Yes. The C# Barcode Reader component support 2-digit and 5-digit add-on symbol in EAN/UPC, ISBN, ISSN barcode images. The barcode library will automatically append the detected add-on data code to the end of the main barcode data code in the C# applications.

Can I print GS1 barcodes in C# application also?

No. You cannot create and encode GS1 barcodes in C# project using C# Barcode Reader library. OnBarcode provides C# Barcode Generation library, which you can generate and print GS1 barcodes in your C# ASP.NET, MVC, console and Windows applications.

Does C# Barcode Scanner library support both ISO and GS1 standards for QR Code and Data Matrix?

Yes. OnBarcode C# Barcode Reader library supports reading and scanning both ISO and GS1 standard QR Code and Data Matrix 2d barcodes in C# applications.

Does C# Barcode Scanner SDK support decoding GS1 barcodes from video feeds?

Yes. OnBarcode C# Barcode recognition SDK supports scanning and detecting GS1 barcodes from live video feeds. You can install and use other library to capture image frames from live video feeds, and the barcode reader library will scan and recogize the GS1 barcodes from them in your C# ASP.NET, MVC, console, WPF and Windwos applications.

How to get a free trial license to scan GS1 barcodes?

You can download and install free trial C# Barcode Reader nuget package from NuGet Package Manager in Visual Studio. Or you can download the free trail package from website directly, and add the downloaded barcode dll to your .net project reference manually.

What extra libraries are needed to build a GS1 barcode scanner ASP.NET or WinForms application?

C# Barcode Decoding component includes all necessary functions to scan, detect and decode GS1 barcodes from image files in C# ASP.NET Core, MVC web or desktop applications. If you need read and decode GS1 barcodes from Adobe PDF, MS Office Word, Excel, PowerPoint file, you need 3rd party libraries to load and export the documents to image files in C# application.




































Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.