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
Scanto extract raw barcodes' data in string array format. - Detailed Scanning: Use method
ScanInDetailsto 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
FileNotFoundExceptionin VB.NET. - Match the
BarcodeTypeparameter 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
Using scanning options, you can optimize barcode scanning speed and recognition rate for VB.NET console, Windows Forms and WPF image processing modules.
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
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 defaultUTF-8encoding 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:
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:
- Prepare the target image file containing mixed barcodes (e.g. QR Code, Code 128).
- Call the
ScanInDetailsmethod of theBarcodeScannerclass. - Pass the image path and a generic list of target barcode types as parameters.
- 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} )
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.
The Barcode Reader SDK provides two methods to scan a single barcode per image in VB.NET project.
- Method 1: Enable
ScanSingleto 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.
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.
- Create a list of
SRegion(scanning region, a structure that defines rectangular coordinates for targeted barcode detection). - For each region, define the X, Y, width, and height values for your target region.
-
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:
- Ensure SRegion coordinates (X, Y, Width, Height) are within the image bounds. More details, see Scan barcodes from cropped image using C#
- Invalid region coordinates will return empty results or cause runtime errors.
- 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
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
Here is the Visual Basic code to configure
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.
The barcode scanning results
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:- ScanDirectionType.All
- ScanDirectionType.Horizontal
- ScanDirectionType.LeftToRight
- ScanDirectionType.LeftToRight Or ScanDirectionType.TopToBottom
The barcode scanning results
| ScanDirectionType.All | ScanDirectionType.LeftToRight
| ScanDirectionType.TopToBottom |
![]() |
![]() |
| ScanDirectionType.LeftToRight | ScanDirectionType.Horizontal |
![]() |
![]() |
Step 4: Core Analysis Conclusions
- 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. - More scanning directions result in longer processing time.
Example: Horizontal (2 directions) is slower than LeftToRight (1 direction). - Most processing time is spent on candidate barcode verification.
- 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 theStepInterval 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).
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
-
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.
- 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.
-
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:
We have provided detailed instructions on parsing special text string using .NET Barcode Reader library. View details here:
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.
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.
- Create a
ScanOptionsinstance and define the target barcode format (QR Code). - Call
SetMaxMultiThreadCount()to set the maximum thread count. - Pass an array of image file paths to the
BarcodeScanner.Scan()method with scan options applied. - 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:
- Do not set an excessively high thread count. It may cause high CPU/memory usage in Windows Forms / WPF applications.
- Multi-threading works best for batch image scanning in VB.NET desktop applications.
VB.NET Barcode Reader Supported Barcode Types
Barcode Reader Library for VB.NET - Barcode Image Reading
- Read Linear / 1D Barcode Images:
- Read Matrix / 2D Barcode Images: Data Matrix, PDF-417, QR Code
| Australia Post | Codabar | Code 39 | Code 93 | Code 128 |
| EAN 8 | EAN 13 | GS1 128 (UCC/EAN128) | Identcode | Intelligent Mail |
| Interleaved 2 of 5 | ISBN | ISSN | ITF-14 | Leitcode |
| Patch Code | Planet | Postnet | RM4SCC | UPC-A |
| UPC-E |








