LEADTOOLS Barcode (Leadtools.Barcode assembly)
LEAD Technologies, Inc

BarcodeEngine Class

Example 







Members 
Main class for the LEADTOOLS support for reading and writing barcodes. .NET support WinRT support Silverlight support
Object Model
BarcodeEngine ClassBarcodeReader ClassBarcodeWriter Class
Syntax
public class BarcodeEngine 
'Declaration
 
Public Class BarcodeEngine 
'Usage
 
Dim instance As BarcodeEngine
public sealed class BarcodeEngine 
ObjectiveC Syntax
Java Syntax
function Leadtools.Barcode.BarcodeEngine()
public ref class BarcodeEngine 
Remarks

The BarcodeEngine class is the main entry point for LEADTOOLS support for barcode reading and writing.

This class contains the following members:

This class also contains the following helper static (Shared in Visual Basic) methods:

To start using LEADTOOLS barcode support, first create an instance of BarcodeEngine. This will automatically create the BarcodeReader and BarcodeWriter objects for you. You can then access those objects through BarcodeEngine.Reader and BarcodeEngine.Writer to start reading or writing barcodes.

All these objects are thread-safe and you can pass the same BarcodeEngine, BarcodeReader or BarcodeWriter object to multiple threads. Additionally, you may read or write barcodes at the same time from/to different images and also create a separate BarcodeEngine for each thread if required. The BarcodeReader.ReadBarcodes(RasterImage image, LogicalRectangle searchBounds, int maximumBarcodes, BarcodeSymbology[] symbologies, BarcodeReadOptions[] options) example shows how to create two threads: One for reading horizontal barcodes and one for reading vertical barcodes. It will then use the same BarcodeReader to try and read all the barcodes from an image using both threads.

For a list of the barcode symbologies supported by LEADTOOLS, refer to Supported Barcode Symbologies.

For tutorials on using LEADTOOLS barcode support, refer to Reading Barcodes Tutorial and Writing Barcodes Tutorial.

Example
Copy CodeCopy Code  
Public Sub BarcodeEngine_Example()
      Dim imageFileNames() As String = _
      { _
         Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif"), _
         Path.Combine(LEAD_VARS.ImagesDir, "Barcode2.tif") _
      }

      ' Create a Barcode engine
      Dim engine As New BarcodeEngine()

      ' Load the image
      Using codecs As New RasterCodecs()
         For Each imageFileName As String In imageFileNames
            Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
               ' Read all the barcodes in this image
               Dim barcodes() As BarcodeData = engine.Reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing)

               ' Print out the barcodes we found
               Console.WriteLine("{0} contains {1} barcodes", imageFileName, barcodes.Length)
               For i As Integer = 0 To barcodes.Length - 1
                  Dim barcode As BarcodeData = barcodes(i)
                  Console.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value)
               Next
               Console.WriteLine("-----------------")
            End Using
         Next
      End Using
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void BarcodeEngine_Example()
   {
      string[] imageFileNames =
      {
         Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif"),
         Path.Combine(LEAD_VARS.ImagesDir, "Barcode2.tif")
      };

      // Create a Barcode engine
      BarcodeEngine engine = new BarcodeEngine();

      // Load the image
      using(RasterCodecs codecs = new RasterCodecs())
      {
         foreach(string imageFileName in imageFileNames)
         {
            using(RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
            {
               // Read all the barcodes in this image
               BarcodeData[] barcodes = engine.Reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null);

               // Print out the barcodes we found
               Console.WriteLine("{0} contains {1} barcodes", imageFileName, barcodes.Length);
               for(int i = 0; i < barcodes.Length; i++)
               {
                  BarcodeData barcode = barcodes[i];
                  Console.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value);
               }
               Console.WriteLine("-----------------");
            }
         }
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
[TestMethod]
public async Task BarcodeEngine_Example()
{
   string[] imageFileNames =
   {
      @"Assets\Barcode1.tif",
      @"Assets\Barcode2.tif"
   };
   // Create a Barcode engine
   BarcodeEngine engine = new BarcodeEngine();

   // Load the image
   using(RasterCodecs codecs = new RasterCodecs())
   {
      foreach(string imageFileName in imageFileNames)
      {
         StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(imageFileName);
         using(RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)))
         {
            // Read all the barcodes in this image
            BarcodeData[] barcodes = engine.Reader.ReadBarcodes(image, LeadRectHelper.Empty, 0, null);
            if (barcodes == null)
            {
               Debug.WriteLine("No barcodes found");
               return;
            }

            // Print out the barcodes we found
            Debug.WriteLine("{0} contains {1} barcodes", imageFileName, barcodes.Length);
            for(int i = 0; i < barcodes.Length; i++)
            {
               BarcodeData barcode = barcodes[i];
               Debug.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value);
            }
            Debug.WriteLine("-----------------");
         }
      }
   }
}
public void BarcodeEngine_Example(RasterImage image, string imageFileName)
{
   // Create a Barcode engine
   BarcodeEngine engine = new BarcodeEngine();
   // Load the image
   RasterCodecs codecs = new RasterCodecs();

   // Read all the barcodes in this image
   BarcodeData[] barcodes = engine.Reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null);

   // Print out the barcodes we found
   Console.WriteLine("{0} contains {1} barcodes", imageFileName, barcodes.Length);
   for(int i = 0; i < barcodes.Length; i++)
   {
      BarcodeData barcode = barcodes[i];
      Console.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value);
   }
   Console.WriteLine("-----------------");
}
Public Sub BarcodeEngine_Example(ByVal image As RasterImage, ByVal imageFileName As String)
   ' Create a Barcode engine
   Dim engine As BarcodeEngine = New BarcodeEngine()
   ' Load the image
   Dim codecs As RasterCodecs = New RasterCodecs()

   ' Read all the barcodes in this image
   Dim barcodes As BarcodeData() = engine.Reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing)

   ' Print out the barcodes we found
   Console.WriteLine("{0} contains {1} barcodes", imageFileName, barcodes.Length)
   Dim i As Integer = 0
   Do While i < barcodes.Length
      Dim barcode As BarcodeData = barcodes(i)
      Console.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value)
      i += 1
   Loop
   Console.WriteLine("-----------------")
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

BarcodeEngine Members
Leadtools.Barcode Namespace
BarcodeReader Class
BarcodeWriter Class
BarcodeSymbology Enumeration
BarcodeData Class
BarcodeReader.ReadBarcode
BarcodeReader.ReadBarcodes
BarcodeWriter.WriteBarcode
Programming with LEADTOOLS Barcode
Supported Barcode Symbologies
Unlocking Barcode Support
Reading Barcodes Tutorial
Writing Barcodes Tutorial
UPC / EAN Barcodes in LEADTOOLS
2 of 5 Barcodes Barcodes in LEADTOOLS
GS1 DataBar / RSS-14 Barcodes in LEADTOOLS
Code 128 Barcodes in LEADTOOLS
USPS and 4-State Barcodes in LEADTOOLS
MSI Barcodes (Pulse Width Modulated) in LEADTOOLS
Codabar Barcodes in LEADTOOLS
Miscellaneous Barcodes in LEADTOOLS
Datamatrix Barcodes in LEADTOOLS
PDF417 and MicroPDF417 Barcodes in LEADTOOLS
MicroPDF417 Barcodes in LEADTOOLS
QR Barcodes in LEADTOOLS
Writing Barcodes - Bounds and XModule

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Barcode requires a Barcode Module license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features