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.
The above C# code will get all Code-128/GS1-128/EAN-128 barcodes in image file "code128-barcode.gif".
Scan & Read Code-128/GS1-128/EAN-128 Barcodes in VB.NET
Scan and read Code-128/GS1-128/EAN-128 barcode in VB.NET is an easy and simple task. One line of vb.net code finishes the job.
Dim datas() AsString = BarcodeReader.read("c:/code128-barcode.gif", BarcodeReader.CODE128)
The above VB.NET code will get all Code-128/GS1-128/EAN-128 barcodes in image file "code128-barcode.gif".
Optimize Code-128/GS1-128/EAN-128 Barcode Reading Performance in C#.NET & VB.NET
You can customize our .NET barcode reader component, to improve Code-128/GS1-128/EAN-128 barcode reading speed, when you are scanning large image size (like 4mb per image).
Set maxOneBarcodePerPage to true, if there is maximum one barcode per image or per page in tiff or pdf document. If maxOneBarcodePerPage is true, the .net barcode reader library will stop scanning the barcode immediately, once detects one barcode. If maxOneBarcodePerPage is false (default value), the library will use total 5 algorithms and each will scan the whole image from 4 directions.
Scan the partial image instead of the whole file. If the barcode is always located one specified area in the image, you can set and let the library scan that area only. And it will reduce lots of scanning time, CPU and memory usage. You just specify the left top point and right bottom point of the area (the point X, Y values are expressed in percentage of the whole image, so image most left top point is (0%, 0%), and most right bottom point is (100%, 100%)).
The following C# code explains how to scan top 20% of the image and bottom 20% of the image.
OptimizeSetting setting = new OptimizeSetting();
setting.setMaxOneBarcodePerPage(true);
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);
The following VB.NET code explains how to scan top 20% of the image and bottom 20% of the image.
Dim setting As OptimizeSetting = New OptimizeSetting()
setting.setMaxOneBarcodePerPage(True)
Dim top20 As ScanArea = New ScanArea(New Drawing.PointF(0.0F, 0.0F), New Drawing.PointF(100.0F, 20.0F))
Dim bottom20 As ScanArea = New ScanArea(New Drawing.PointF(0.0F, 80.0F), New Drawing.PointF(100.0F, 100.0F))
Dim areas As List(Of ScanArea) = New List(Of ScanArea) areas.Add(top20) areas.Add(bottom20)
setting.setAreas(areas)
Dim datas() AsString = BarcodeReader.read("c:/code128-barcode.gif", BarcodeReader.CODE128, setting)
Scanning Code 128 Barcode Images in Memory
The Scan() method also accepts a Stream object as the input data source.
Scanning Code 128 from Multi Barcode Formats
If the image contains multiple barcodes of different formats, all can be scanned at once. The following example scans for both Code 128 and Code 39 barcodes.
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 BarcodeDetail
The following core information is accessible from the BarcodeDetail object:
Type: Verifies that the scanned barcode is Code 128.
GetMessage(): Returns the decoded Code 128 text string.
GetASCIITextMessage(): Returns the decoded Code 128 ASCII text string, with non printable characters replaced by visible labels.
Code 128 Position, Rotation, Checksum, and Encoding Mode
Additional properties provide detailed information about the scanned Code 128 barcode:
Rotation: The rotation angle of the scanned barcode.
X1, Y1, X2, Y2, X3, Y3, X4, Y4: Pixel coordinates defining the barcode region within the image.
GetBarcodeProps() returns a Code128Props object containing:
StartSet: The start code set (Code Set A, B, or C).
IsMixSet: Indicates whether more than one code set was used during encoding.
Checksum: The checksum codeword (range 0 - 102).
How to Read and 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 GetASCIITextMessage() method.
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.