VB.NET Barcode Reader & Scanner SDK Tutorial


How to scan, read QR Code, Code 128, 2d, 1d barcode images in Visual Basic .NET Windows application?

Reading & Scanning Linear, 2D Barcode Images in VB.NET Windows Forms, WPF, console applications



  • Read and recognize 20+ linear, 2d barcode images in VB.NET
  • Scan and read barcodes from any angle inside the barcode image in any Visual Basic .NET development
  • Decode barcodes from Tiff, Bitmap, Gif, Jpeg image types in VB.net class
  • Support quick scan barcodes from specified area inside the image document
  • Completely developed using C#, compatible with .NET 5+, .NET Standard 2.0, .net framework 4.x, 3.x, and 2.0
  • Detailed tutorials on read barcode in asp.net c#, read barcode in c# windows
  • Reading and recognizing 2d (matrix) barcode images, including QR Code in VB.NET, PDF-417 in VB.NET, Data Matrix in VB.NET.
  • Scanning and recognizing linear (1d) barcode images, including Code 39, Code 128, EAN-13, UPC-A, GS1-128
  • Mature C#.NET barcode reading component SDK


How to read, scan 2d, linear barcode image in VB.NET application

  1. Download .NET Barcode Reader Library
  2. Install VB.NET library to scan barcode images in VB.NET apps
  3. Step by Step Tutorial
















OnBarcode .NET Barcode Reader is a VB.NET component which reads and recognizes barcode images in Visual Studio VB.NET applications.

.NET Barcode Reader is completed built on C# 2005, supporting Code 39, Code 128, GS1-128/EAN-128, Interleaved 2 of 5, UPC-A, UPC-E, EAN-8, EAN-13, and PDF-417.

VB.NET Barcode Generators

VB.NET 2d barcode generators: QR Code Generator, PDF-417 Generator, Data Matrix Generator.
VB.NET linear barcode creators: Create Code 39, Create Code 128, Create EAN-8, Create EAN-13, Create GS1-128, Create ITF-14, Create UPC-A, Create UPC-E.


Quick to scan barcodes in VB.NET WinForms, WPF application

Here we will learn how to quickly scan and read barcodes from image files in VB.NET, applicable to both Windows Forms and WPF projects.

Read barcodes from image file

Two core scanning methods are provided for image file barcode recognition in OnBarcode VB.NET Barcode Reader library:

  • Basic Scanning: Use method Scan to extract raw barcodes' data in string array format.
  • Detailed Scanning: Use method ScanInDetails to extract complete barcode metadata (BarcodeDetail, a structured object containing barcode data, location, and format details).

Dim rawDatas As String() = BarcodeScanner.Scan(
    "code128-barcode.png", BarcodeType.Code128)

Dim detailDatas As BarcodeDetail() = BarcodeScanner.ScanInDetails(
    "code128-barcode.png", BarcodeType.Code128)


Note:
  • Ensure the image file path is an absolute/valid relative path; invalid paths will throw a FileNotFoundException in VB.NET.
  • Match the BarcodeType parameter with the actual scanning barcode type; mismatches will cause scanning failure.
  • This method is fully compatible with VB.NET Windows Forms PictureBox controls and WPF Image controls.



Read barcodes in memory from Stream object

Use the overloaded Scan() and ScanInDetails() methods to read barcodes directly from the Stream object:

Dim imageStream As Stream = GetImageStream()

Dim rawDatas As String() = BarcodeScanner.Scan(imageStream, BarcodeType.Code128)

Dim detailDatas As BarcodeDetail() = BarcodeScanner.ScanInDetails(
    imageStream, BarcodeType.Code128)


Note: Reading barcodes from Stream object in memory is optimized for WPF Image controls and Windows Forms stream-based image rendering.





About ScanOptions and BarcodeDetail

Now we will learn how to customize barcode scanning options and obtaining detailed barcode information in VB.NET desktop applications (Windows Forms / WPF). It implements full-scenario barcode recognition with configurable options and extended metadata output.


ScanOptions

Using OnBarcode VB.NET Barcode Reader library, you can fully customize barcode scanning behavior via ScanOptions (a configuration class for defining scanning options, rules, performance, and accuracy).

Using scanning options, you can optimize barcode scanning speed and recognition rate for VB.NET console, Windows Forms and WPF image processing modules.

Dim options As New ScanOptions(BarcodeType.DataMatrix)
Dim result As BarcodeDetail() = BarcodeScanner.Scan("C://Input//datamatrix.png", options)

Supported Custumization Options

  • SetScanRegions()
    Enables scanning of specified rectangular areas within an image.
    This reduces the scanning range, accelerates processing speed, and improves recognition accuracy.
  • SetMaxMultiThreadCount()
    Enables multi-threaded barcode scanning in VB.NET.
    It optimizes batch processing for Windows Forms and WPF bulk image scenarios.
  • ScanSingle
    Limits the library to detect only one barcode per image.
    It significantly boosts speed when images contain single barcode.
  • EnableGS1
    Enables parsing of GS1 (a universal supply chain barcode standard) data elements.
    Supports GS1 compatible barcodes: QR Code, Data Matrix, GS1-128, GS1 DataBar.
  • ScanDirection
    Specifies the image scanning directions for the barcode library.
    Direct configuration reduces invalid detection and accelerates reading speed.
  • StepInterval
    Defines the line spacing for barcode area search.
    It determines how many pixel lines the library scans in one step.
  • ZoomRatio
    Valid range: 0.2F - 5.0F (default value = 1.0F).
    Applies zoom scaling to the source image before scanning.


BarcodeDetail

BarcodeDetail (a data entity class that stores full barcode metadata) provides extended information beyond raw text data.

It is useful for advanced barcode processing in VB.NET Windows Forms and WPF applications.

Access core properties and methods of BarcodeDetail to extract full barcode metadata:
  • Rotation
    Returns the rotation angle of the detected barcode on the image.
  • X1, Y1, X2, Y2, X3, Y3, X4, Y4
    8 coordinate properties that define the four-corner position of the barcode region.
  • IsStructuredAppend
    Exclusive to QR Code and Data Matrix barcodes.
    Identifies if the barcode uses Structured Append mode (split large data across multiple barcodes).
  • IsGS1Compatible
    Exclusive to QR Code, Data Matrix, and Code 128 barcodes.
    Identifies if the barcode supports GS1 standard data format.
  • isMacroPDF417()
    Exclusive to PDF417 barcodes.
    Verifies if the barcode is in Macro PDF417 format.
  • GetDataBytes()
    Returns the raw barcode data as a byte array.
  • GetMessage() / GetMessage(Encoding enc)
    Returns barcode text using default UTF-8 encoding or a custom encoding format.


Note: IsStructuredAppend and IsGS1Compatible return False for unsupported barcode types.


VB.NET Code: Scan Barcodes and Retrieve Detailed Information

Here we provide a complete VB.NET code example for batch image scanning, configuration application, and detailed barcode data output. It is fully compatible with VB.NET Windows Forms and WPF application.

' Define image directory and batch image files (VB.NET syntax)
Dim folder As String = "C:\Output\"
Dim sourceImageFiles As String() = {
    folder & "SourceImage01.png",
    folder & "SourceImage02.png"
}

' Initialize ScanOptions for DataMatrix barcode scanning
Dim options As New ScanOptions(BarcodeType.DataMatrix)

' Execute batch scanning and return BarcodeDetail array
Dim scanResults As BarcodeDetail() = BarcodeScanner.Scan(sourceImageFiles, options)

' Traverse results and output detailed barcode information
For Each barcodeObj As BarcodeDetail In scanResults
    ' Get barcode text message
    Console.WriteLine("Message: '" & barcodeObj.GetMessage() & "'")
    
    ' Get image index and source file path
    ' SourceFilePath is empty for Stream / Bitmap inputs
    Console.WriteLine("Source: Index=" & barcodeObj.SourceIndex &
                      "; Source Path: " & barcodeObj.SourceFilePath)
Next




Multi-Format Barcode Scanning in VB.NET (Windows Forms & WPF)

The following content demonstrates how to scan and recognize multiple barcode formats from image files and Stream objects using the VB.NET Barcode Reader library.

This feature supports batch barcode recognition in VB.NET desktop applications. It is fully optimized for VB.NET Windows Forms and WPF (.net framework) projects.

Follow these steps to implement multi-format barcode scanning in your VB.NET project:

  1. Prepare the target image file containing mixed barcodes (e.g. QR Code, Code 128).
  2. Call the ScanInDetails method of the BarcodeScanner class.
  3. Pass the image path and a generic list of target barcode types as parameters.
  4. The method returns a BarcodeDetail (scanned barcode detailed information entity) array with complete barcode data.

Dim barcodeDatas As BarcodeDetail() = BarcodeScanner.ScanInDetails(
    "multiple-barcodes.png",
    New List(Of BarcodeType) From {
    BarcodeType.QRCode, BarcodeType.Code128, BarcodeType.EAN13}
)





Scan and read a single barcode from the image using VB.NET

OnBarcode VB.NET Barcode Reader will scan all barcodes in the image by default. The barcode library will load and scan the whole image content, and scan barcodes. However if the image contains only one barcode, you can customize and limit the barcode library to detect only one barcode per image. The barcode library will stop scanning once a barcode detected and decoded a valid barcode value. It will significantly boost barcode reading speed.

The Barcode Reader SDK provides two methods to scan a single barcode per image in VB.NET project.
  • Method 1: Enable ScanSingle to true to scan one single barcode per image
  • Method 2: Call method BarcodeScanner.ScanSingleBarcode() to read one barcode per image file

Dim barcodes As String() = BarcodeScanner.ScanSingleBarcode(
    "code39-image.gif", BarcodeType.Code39)




Scan Barcodes from a Specified Region or Cropped Image in VB.NET

Here we will explain how to scan barcodes from custom specified regions in images to boost reading speed in your Visual Basic .NET applications.

Using OnBarcode VB.NET Barcode Reader library, you can improve barcode reading speed by scanning only a defined rectangular area of an image.

This reduces the scanning range and increases processing efficiency.

  1. Create a list of SRegion (scanning region, a structure that defines rectangular coordinates for targeted barcode detection).
  2. For each region, define the X, Y, width, and height values for your target region.
  3. Call the BarcodeScanner.ScanRegions() method to scan within the defined area.

Dim region As New List(Of SRegion)()
region.Add(New SRegion(0, 0, 50, 60))

Dim barcodes As String() = BarcodeScanner.ScanRegions(
    "qrcode-barcodes.png", BarcodeType.QRCode, region)


Note:
  1. Ensure SRegion coordinates (X, Y, Width, Height) are within the image bounds. More details, see Scan barcodes from cropped image using C#
  2. Invalid region coordinates will return empty results or cause runtime errors.
  3. This method works for both image files and Stream objects in WinForms and WPF.




Improve barcode reading performance with customized scanning directions

The VB.NET Barcode Reader library supports customized scanning directions. You can define these directions using the ScanDirection property in the ScanOptions (scanning configuration class).

Here we provide step-by-step instructions for configuring barcode scanning directions and performing performance testing in VB.NET (Visual Basic .NET) desktop applications.

The ScanDirectionType (enum that defines all supported barcode scanning directions) includes the following options:
  • Undefined: Default value, equivalent to All.
  • LeftToRight: Scans the image from left to right.
  • TopToBottom: Scans the image from top to bottom.
  • RightToLeft: Scans the image from right to left.
  • BottomToTop: Scans the image from bottom to top.
  • Horizontal: Combines LeftToRight and RightToLeft scanning.
  • Vertical: Combines TopToBottom and BottomToTop scanning.
  • All: Scans from all four directions (left-right, right-left, top-bottom, bottom-top).

Here is the Visual Basic code to configure ScanOptions to scan Code 128 barcodes from two directions.

Dim scanOps As New ScanOptions(BarcodeType.Code128)
scanOps.ScanDirection = ScanDirectionType.LeftToRight Or ScanDirectionType.TopToBottom


Barcode Scanning Direction Performance Testing

Here we will demonstrate a performance test to compare scanning speed across different direction modes in VB.NET.

Step 1: Create a VB.NET method to perform a single round of barcode scanning.

Private Shared Sub ReadBarcodeSingleRound()
    ' Initialize scanning configuration
    Dim scanOps As New ScanOptions(BarcodeType.Code128)
    
    ' Configure different scanning directions (uncomment one only)
    scanOps.ScanDirection = ScanDirectionType.All
    'scanOps.ScanDirection = ScanDirectionType.Horizontal
    'scanOps.ScanDirection = ScanDirectionType.LeftToRight
    'scanOps.ScanDirection = ScanDirectionType.LeftToRight Or ScanDirectionType.TopToBottom
    
    ' Execute scanning with the configured options
    Dim scanResult As BarcodeDetail() = BarcodeScanner.Scan(
       "C:\Input\barcode-code128-demo-image.png", scanOps)
    
    ' Output scanning results
    If scanResult.Length > 0 Then
        Debug.WriteLine("Count: {scanResult.Length}")
        For Each barcode As BarcodeDetail In scanResult
            Debug.WriteLine("Message: '{barcode.GetMessage()}'")
        Next
    Else
        Debug.WriteLine("No Barcode Found.")
    End If
End Sub


Step 2: Run the scanning test 10 consecutive times and measure total execution time.

' Initialize stopwatch for performance measurement
Dim stopwatch As New Stopwatch()
stopwatch.Start()

' Repeat scanning test 10 rounds
For round As Integer = 0 To 9
    ReadBarcodeSingleRound()
Next

stopwatch.Stop()

' Calculate and display total time and average time
Dim totalTime As Single = CSng(stopwatch.ElapsedMilliseconds) / 1000.0F
Dim averageTime As Single = totalTime / 10.0F
Debug.WriteLine("Time: {totalTime:F3}s; Ave.: {averageTime:F3}s")


Step 3: Scanning Direction Performance Result Analysis

We have tested the following scanning directions combinations:
  1. ScanDirectionType.All
  2. ScanDirectionType.Horizontal
  3. ScanDirectionType.LeftToRight
  4. ScanDirectionType.LeftToRight Or ScanDirectionType.TopToBottom

The barcode scanning results

ScanDirectionType.All ScanDirectionType.LeftToRight
|
ScanDirectionType.TopToBottom
ScanDirectionType.LeftToRight ScanDirectionType.Horizontal


Step 4: Core Analysis Conclusions

  1. Select the scanning direction based on the barcode's rotation angle.
    Non-rotated barcodes: Use LeftToRight or RightToLeft direction.
    90-degree rotated barcodes: Use TopToBottom or BottomToTop direction.
  2. More scanning directions result in longer processing time.
    Example: Horizontal (2 directions) is slower than LeftToRight (1 direction).
  3. Most processing time is spent on candidate barcode verification.
  4. Time differences between multi-direction modes are relatively small.
    Example: 2-direction vs 4-direction modes show minimal time gap.




Improve barcode reading performance with customized scanning directions

Here we will learn how to use the StepInterval property to optimize barcode scanning speed with real example data in VB.NET desktop applications.

StepInterval Configuration in ScanOptions

When the VB.NET Barcode Reader library scans barcodes from a raster image (pixel-based image file), it processes the image pixel data line by line. You can control the scanning density using the StepInterval property in the ScanOptions (scanning configuration parameter class).

  • StepInterval: Defines the scanning line spacing.
  • It determines how many pixel lines the library skips between each scan pass.
  • Minimum value: 1 (scans every single pixel row).
  • Default value: 5 (scans one line, then skips the next 4 lines).
Here is the VB.NET example source code to scan barcode images using different StepInterval values.

' Initialize ScanOptions for Code 128 barcode scanning
Dim scanOps As New ScanOptions(BarcodeType.Code128)

' Set scanning direction
scanOps.ScanDirection = ScanDirectionType.LeftToRight

' Set StepInterval value (uncomment one mode to test)
scanOps.StepInterval = 5   ' Default value
'scanOps.StepInterval = 1  ' Scan all lines (highest accuracy)
'scanOps.StepInterval = 10 ' Larger interval (faster speed)
'scanOps.StepInterval = 83 ' Maximum test interval


Scanning Results & Performance Analysis

Scanning result data with different step intervals applied

StepInterval = 1 StepInterval = 5
StepInterval = 10 StepInterval = 83


Test Result Analysis

  1. Speed vs Interval Relationship
    • A larger StepInterval value reduces scanning time.
    • Example: StepInterval=1 (0.257s) vs StepInterval=5 (0.151s).
    • Fewer lines to check directly improves processing speed.
  2. Detection Risk of Large Intervals
    • An excessively large interval may skip the barcode completely.
    • This causes no barcode detected errors.
    • Risk depends on barcode height and vertical position.
  3. Failure Example
    • In the demo image, StepInterval = 83 prevents barcode detection.
    • The library skips all lines containing barcode pixels.




Scan and Parse Complex Barcode Text Message in VB.NET

2d and 1d barcodes may encode formated text. When you are scanning and reading QR Code or 2d, linear barcodes with structured text in vb.net, you need parse the barcode raw data specially.

We have provided detailed instructions on parsing special text string using .NET Barcode Reader library. View details here:

Scan, decode Unicode text from 2d barcodes in VB.NET





Read, parse GS1 text message from GS1 barcodes (QR Code, Data Matrix, GS1-128) in VB.NET





Read add-on code from EAN/UPC barcode in VB.NET





Multi-thread Barcode Scanning in VB.NET

Here we will show how to implement multi-threaded barcode scanning for multiple image files to boost processing speed in vb.net console, Windows Forms and WPF applications.

It is designed for VB.NET (Visual Basic .NET) development environments and fully supports Windows Forms (WinForms, traditional desktop UI framework) and WPF (Windows Presentation Foundation, modern .NET UI framework) applications.

  1. Create a ScanOptions instance and define the target barcode format (QR Code).
  2. Call SetMaxMultiThreadCount() to set the maximum thread count.
  3. Pass an array of image file paths to the BarcodeScanner.Scan() method with scan options applied.
  4. Traverse the BarcodeDetail (barcode detailed information entity) array to process scanning results.
' Initialize scanning configuration with target barcode type
Dim scanOptions As New ScanOptions(BarcodeType.QRCode)

' Set maximum multi-threading count (3 concurrent threads)
' Value must be non-negative
' 0 = disable multi-threading (default)
' >0 = enable multi-threaded scanning
scanOptions.SetMaxMultiThreadCount(3)

' Define batch image files array
Dim imageFiles As String() = {
    "SourceImage01.png",
    "SourceImage02.png",
    "SourceImage03.png"
}

' Execute multi-threaded batch scanning
Dim scanResults As BarcodeDetail() = BarcodeScanner.Scan(imageFiles, scanOptions)

' Process and parse all scanning results
For Each barcodeObj As BarcodeDetail In scanResults
    ' Process barcode data / display results in Windows Forms/WPF UI
Next


Note:
  1. Do not set an excessively high thread count. It may cause high CPU/memory usage in Windows Forms / WPF applications.
  2. Multi-threading works best for batch image scanning in VB.NET desktop applications.


How to scan, read rotated, colored barcode and QR Code with logo image in VB?

OnBarcode VB.NET Barcode Reader library automatically supports the following barcodes in VB.NET web and desktop application.
  • Rotated barcode
  • Colored barcode
  • Styled QR Code with logo image inside

Read rotated barcode in VB.NET





Read colored barcode in VB.NET





Read styled QR Code with logo image in VB.NET





VB.NET Barcode Reader Supported Barcode Types

Barcode Reader Library for VB.NET - Barcode Image Reading





































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