←Select platform

ReadBarcode(RasterImage,LogicalRectangle,BarcodeSymbology) Method

Summary

Read one barcode from an image with specified symbology and default options.

Syntax

C#
VB
Java
Objective-C
WinRT C#
C++
- (nullable LTBarcodeData *)readBarcode:(LTRasterImage *)image 
                           searchBounds:(LeadRect)searchBounds 
                              symbology:(LTBarcodeSymbology)symbology 
                                  error:(NSError **)error 
             
public BarcodeData readBarcode( 
  RasterImage image,  
  LeadRect searchBounds,  
  BarcodeSymbology symbology 
) 
             
 function Leadtools.Barcode.BarcodeReader.ReadBarcode(RasterImage,LogicalRectangle,BarcodeSymbology)(  
   image , 
   searchBounds , 
   symbology  
) 

Parameters

image
A RasterImage object that contains the image data. Must not be null (Nothing in VB).

searchBounds
A LogicalRectangle that specifies the region of interest area in the image where the barcode search and detection is performed. You can specify LogicalRectangle.Empty to indicate that the search must be performed on the whole image.

symbology
A BarcodeSymbology enumeration member that specifies the barcode symbology (type) to search for. You can pass BarcodeSymbology.Unknown to search for all available symbologies in this BarcodeReader.

Return Value

An instance of BarcodeData or one of its derived classes that contains the symbology, data, location and any rotation angle of the barcode found. If no barcodes can be found, then this method will return null (Nothing in VB).

Remarks

Use these methods if you want to read a single barcode from the image, for example, a QR symbol by specifying BarcodeSymbology.QR or if you want to read any barcode found regardless of its type by using BarcodeSymbology.Unknown.

For more information on barcode reading, refer to BarcodeReader.

This method will use the default read options set in this BarcodeReader that correspond to symbology. If the value of this parameter is BarcodeSymbology.Unknown, then all the default read options might be used.

LEADTOOLS barcode read engine is optimized for speed and can search for multiple similar symbologies at the same time. This method simply returns the first barcode that is detected correctly using the symbology and current options.

The ReadSymbology event will occur before and after attempting to read any symbology. The read options being used whether the default or specified will be set in the BarcodeReadSymbologyEventArgs.Options property of the event data.

The BarcodeReader provides the following barcode read methods:

Method Description
ReadBarcode(RasterImage image, LogicalRectangle searchBounds, BarcodeSymbology symbology) and ReadBarcode(RasterImage image, LogicalRectangle searchBounds, BarcodeSymbology symbology, BarcodeReadOptions options)

Read one barcode from an image with specified symbology and default or specific options. Use these methods if you want to read a single barcode from the image, for example, a QR symbol by specifying BarcodeSymbology.QR or if you want to read any barcode found regardless of its type by using BarcodeSymbology.Unknown.

ReadBarcode(RasterImage image, LogicalRectangle searchBounds, BarcodeSymbology[] symbologies) and ReadBarcode(RasterImage image, LogicalRectangle searchBounds, BarcodeSymbology[] symbologies, BarcodeReadOptions[] options)

Read one barcode from an image with a symbology from a specified group and default or specific options. Use these methods if you want to read a single barcode from a known group. For example, to read a barcode that can be of any UPC type, pass an array of BarcodeSymbology.UPCA and BarcodeSymbology.UPCE.

ReadBarcodes(RasterImage image, LogicalRectangle searchBounds, int maximumBarcodes, BarcodeSymbology[] symbologies) and ReadBarcodes(RasterImage image, LogicalRectangle searchBounds, int maximumBarcodes, BarcodeSymbology[] symbologies, BarcodeReadOptions[] options)

Read multiple barcodes from an image with symbologies from a specified group and default or specific options. Use these methods if you want to read multiple barcodes of the same or multiple symbologies.

Example

This example shows how to use this method to read a single barcode from an image.

C#
VB
Silverlight C#
Silverlight VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
 
public void BarcodeReader_ReadBarcodeExample1() 
{ 
   string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Barcode2.tif"); 
 
   // Create a Barcode engine 
   BarcodeEngine engine = new BarcodeEngine(); 
 
   // Get the Barcode reader instance 
   BarcodeReader reader = engine.Reader; 
 
   // Load the image 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)) 
      { 
         // Read the QR barcode from this image 
         BarcodeData barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR); 
 
         // Show its location and data if found 
         if (barcode != null) 
         { 
            Console.WriteLine("Found at {0}, data:\n{1}", barcode.Bounds, barcode.Value); 
         } 
         else 
         { 
            Console.WriteLine("Not found"); 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms 
Imports Leadtools.Barcode 
Imports Leadtools.ImageProcessing 
 
Public Sub BarcodeReader_ReadBarcodeExample1() 
   Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Barcode2.tif") 
 
   ' Create a Barcode engine 
   Dim engine As New BarcodeEngine() 
 
   ' Get the Barcode reader instance 
   Dim reader As BarcodeReader = engine.Reader 
 
   ' Load the image 
   Using codecs As New RasterCodecs() 
      Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1) 
         ' Read the QR barcode from this image 
         Dim barcode As BarcodeData = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR) 
 
         ' Show its location and data if found 
         If Not IsNothing(barcode) Then 
            Console.WriteLine("Found at {0}, data:\n{1}", barcode.Bounds, barcode.Value) 
         Else 
            Console.WriteLine("Not found") 
         End If 
      End Using 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
using Leadtools.Examples; 
 
public void BarcodeReader_ReadBarcodeExample1(RasterImage image) 
{ 
   // Create a Barcode engine 
   BarcodeEngine engine = new BarcodeEngine(); 
 
   // Get the Barcode reader instance 
   BarcodeReader reader = engine.Reader; 
 
   // Load the image 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Read the QR barcode from this image 
   BarcodeData barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR); 
 
   // Show its location and data if found 
   if (barcode != null) 
   { 
      Console.WriteLine("Found at {0}, data:\n{1}", barcode.Bounds, barcode.Value); 
   } 
   else 
   { 
      Console.WriteLine("Not found"); 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms 
Imports Leadtools.Barcode 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
 
Public Sub BarcodeReader_ReadBarcodeExample1(ByVal image As RasterImage) 
   ' Create a Barcode engine 
   Dim engine As BarcodeEngine = New BarcodeEngine() 
 
   ' Get the Barcode reader instance 
   Dim reader As BarcodeReader = engine.Reader 
 
   ' Load the image 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   ' Read the QR barcode from this image 
   Dim barcode As BarcodeData = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR) 
 
   ' Show its location and data if found 
   If Not barcode Is Nothing Then 
      Console.WriteLine("Found at {0}, data:" & Constants.vbLf & "{1}", barcode.Bounds, barcode.Value) 
   Else 
      Console.WriteLine("Not found") 
   End If 
End Sub 

Requirements

Target Platforms

Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
Leadtools.Barcode Assembly
Click or drag to resize