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


Home > .NET Barcode Reader > .NET Barcode Reading Guide > .NET Code-128/GS1-128/EAN-128 Barcode Reader for C#, VB.NET Applications

C#: How to scan, read Code 128 barcodes in C# ASP.NET, Windows application?

Scan & Read Code-128/GS1-128/EAN-128 barcodes in C# ASP.NET, MVC, Windows application?

  • Easily read & scan Code-128/GS1-128/EAN-128 barcodes in .NET applications
  • Reading Code-128/GS1-128/EAN-128 barcode images in JPEG, GIF, PNG, BMP, TIFF formats
  • 100% build in C#.net, compatible with .NET 2.0 and later versions
  • Complete sample C#.net, VB.net sample codes for C# & VB.NET developers
  • Mature Code 128 .NET Barcode Reader Component since 2003
The C# Code 128 Reader SDK is a high performance linear and 2D barcode recognition SDK for Microsoft Visual Studio .NET platforms. Scanning and reading Code 128 barcodes from image files is one of the barcode decoding functions provided by the .NET Barcode Scanner component. To assist .NET developers in integrating the barcode reader control into their projects, detailed online tutorials are available.

C# Code 128 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


How to Read Code 128 barcode in C#?

Using BarcodeLib C# Barcode Scanner library, you can quickly read and recognize Code 128 barcode from an image file in C# application.
  1. Create a OptimizeSetting with scanning barcode type BarcodeReader.CODE128 specified.
  2. Use method BarcodeReader.ReadBarcode() to scan Code 128 barcode from image file, Stream object, or Bitmap object.
OptimizeSetting options = new OptimizeSetting(BarcodeReader.CODE128);
BarCode[] datas = BarcodeReader.ReadBarcode("code128-barcode-sample.png", options);
foreach (BarCode aBarcode in datas)
{
    String data = aBarcode.GetMessage();
}

Note: The BarcodeReader.ReadBarcode() method also accepts a Stream and Bitmap object as the input barcode image data source.


Read multiple Code 128 barcodes from an image file

C# Barcode Reader Library will automatically scan and detect all valid Code 128 barcodes from a single image file.



Scan, read Code 128 and other barcode formats in C#

You can scan and recognize Code 128 and other barcode types at one time from a single image file in C# program.
  • Specify all target barcode types in OptimizeSetting object
OptimizeSetting options = new OptimizeSetting(new int[] {
    BarcodeReader.CODE128,
    BarcodeReader.EAN13,
    BarcodeReader.CODE39,
    BarcodeReader.QRCODE });



How to Scan, Read GS1-128 Barcodes in C#

When you are reading Code 128 barcodes, you can choose to scan and return GS1-128 barcodes only in the C# application.
  • In OptimizeSetting object, use method setReadGS1Barcode(true) to scan and read GS1-128 barcodes only.
  • In BarCode object, use property IsGS1Compitable to check whether it is a GS1-128 barcode or a Code 128.
OptimizeSetting options = new OptimizeSetting(BarcodeReader.CODE128);
options.setReadGS1Barcode(true);
BarCode[] datas = BarcodeReader.ReadBarcode("gs1-128-barcode-sample.png", options);
foreach (BarCode aBarcode in datas)
{
    if (aBarcode.IsGS1Compitable)
    {
        String data = aBarcode.GetMessage();
    }
}



How to Retrieve Scanned Code 128 Barcode Properties in C#

Using the Barcode Reader library, scanned Code 128 barcode information can be retrieved, including the decoded text message, verified barcode format, position within the image, start code set, and checksum codeword value.


Extract Code 128 Core Information from BarCode

The following core information is accessible from the BarCode object:
  • GetTypeName(): Verifies that the scanned barcode is Code 128.
  • GetMessage(): Returns the decoded Code 128 text string.
  • GetMessageInASCII(): Returns the decoded Code 128 ASCII text string, with non printable characters replaced by visible labels.
  • IsGS1Compitable: Verifies that the Code 128 barcode is GS1-128
  • Corners: Pixel coordinates defining the Code 128 barcode region within the image.
OptimizeSetting options = new OptimizeSetting(BarcodeReader.CODE128);
BarCode[] datas = BarcodeReader.ReadBarcode("code128-barcodes-sample.png", options);
foreach (BarCode aBarcode in datas)
{
    String barcodeTypeName = aBarcode.GetTypeName();
    String data = aBarcode.GetMessage();
    String dataAscii = aBarcode.GetMessageInASCII();
    bool isGs1Code128 = aBarcode.IsGS1Compitable;
    PointF[] barcodePosition = aBarcode.Corners;
}


Code 128 Checksum, and Encoding Information

Additional properties provide detailed information about the scanned Code 128 barcode from object Code128Info.

getBarcodeExtraInfos() returns a Code128Info object containing:
  • getFirstSet(): The Code 128 start code set (Code Set A, B, or C).
  • hasMultiSets(): Indicates whether more than one code set was used during Code 128 encoding.
  • getChecksum(): The Code 128 checksum codeword (range 0 - 102).
OptimizeSetting options = new OptimizeSetting(BarcodeReader.CODE128);
BarCode[] datas = BarcodeReader.ReadBarcode("code128-barcodes-sample.png", options);
foreach (BarCode aBarcode in datas)
{
    Code128Info barcodeInfo = (Code128Info)aBarcode.getBarcodeExtraInfos();
    Code128Set startSet = barcodeInfo.getFirstSet();
    bool isMutlipleSets = barcodeInfo.hasMultiSets();
    int checksumCodeword = barcodeInfo.getChecksum();
}


How to Read, Process Scanned Code 128 ASCII Text in C#

Code 128 supports full 128 ASCII character encoding, including 95 printable characters and 33 control (non printable) characters. The following example demonstrates scanning a Code 128 barcode that contains the carriage return character ([CR]), which has ASCII value 13.

To obtain non printing ASCII characters replaced with visible text labels, use the GetMessageInASCII() method.

OptimizeSetting options = new OptimizeSetting(BarcodeReader.CODE128);
BarCode[] datas = BarcodeReader.ReadBarcode("code128-barcode-sample.png", options);
foreach (BarCode aBarcode in datas)
{
    String data = aBarcode.GetMessageInASCII();
}



Verifying Scanned Code 128 Barcode Data Using the Check Character

Code 128 includes a mandatory check character. When using the Barcode Reader library, only the data characters are returned; the check character is not included. The library automatically verifies the scanned data against the check character, and if verification fails, the data is not returned.


Summary

This tutorial has provided a comprehensive guide to integrating Code 128 barcode reading capabilities into .NET applications using C# and VB.NET. Developers can use the BarcodeLib Barcode Reader SDK to scan and decode Code 128 symbols from image files, extract detailed barcode properties including position, rotation, and encoding information, and handle ASCII text with control characters.

The barcode scanner component seamlessly integrates into ASP.NET web applications, WinForms desktop applications, and WPF based solutions, enabling robust Code 128 barcode reading functionality across multiple .NET environments. For challenging images, techniques such as zoom scaling and quiet zone enhancement can significantly improve recognition success rates.