LEAD Technologies, Inc

Using the LEADTOOLS Barcode Read Activity

Take the following steps to create and run a program that uses the LEADTOOLS Barcode read activity to recognize barcodes in an image:

  1. Start Visual Studio .NET.
  2. Choose File->New->Project... from the menu.
  3. In the New Project dialog box, choose either "Visual C#" or "Visual Basic" then "Workflow" in the Projects Type List, and choose "Sequential Workflow Console Application" in the Templates List.
  4. Type the project name as "WfBarcodeReadTest" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK.
  5. In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference..." from the context menu. In the "Add Reference..." dialog box, select the ".NET" tab, browse to the "C:\LEADTOOLS 17.5\Bin\DotNet\Win32 " folder and select the following DLLs:
    • Leadtools.Workflow.Raster.dll
    • Leadtools.Workflow.Barcode.dll
    Click Select and then click OK to add the above DLLs to the application.
  6. To add the LEADTOOLS activities to your toolbox, right-click the toolbox and select "Choose Items". In the "Choose Toolbox Items" dialog, go the "Activities" tab, and browse for and select the same DLLs in step (5).
  7. Double-click your project's workflow to open it for editing, then select the UnlockSupportActivity, LoadImageActivity and BarcodeReadActivity activities from the toolbox and place them on the workflow in that order.
  8. Add a handler to the workflow's Initialized event and add the below code to it:

                   [C#]
                
                   unlockSupportActivity1.UnlockedFeatures.Add(Leadtools.Workflow.Raster.RasterSupportType.Barcodes1D, "Replace with your own key here");
                   barcodeReadActivity1.MajorType = Leadtools.Workflow.Barcode.BarcodeMajorTypeFlags.Barcodes1d;
                   barcodeReadActivity1.SearchType = Leadtools.Workflow.Barcode.BarcodeSearchTypeFlags.Barcode1dReadAnyType;
                   barcodeReadActivity1.BarColor = Color.Black;
                   barcodeReadActivity1.SpaceColor = Color.White;
                 
    
                   [Visual Basic]
                
                   unlockSupportActivity1.UnlockedFeatures.Add(Leadtools.Workflow.Raster.RasterSupportType.Barcodes1D, "Replace with your own key here")
                   barcodeReadActivity1.MajorType = Leadtools.Workflow.Barcode.BarcodeMajorTypeFlags.Barcodes1d
                   barcodeReadActivity1.SearchType = Leadtools.Workflow.Barcode.BarcodeSearchTypeFlags.Barcode1dReadAnyType
                   barcodeReadActivity1.BarColor = Color.Black
                   barcodeReadActivity1.SpaceColor = Color.White
                 
    
  9. Set the Url property of the LoadImageActivity to "C:\LEADTOOLS 17.5\Images\Barcode1.TIF".
  10. Bind the Image property of the BarcodeReadActivity to the Image property of the LoadImageProperty.
  11. Set the DisposeImage property of the BarcodeReadActivity to True.
  12. Right-click your workflow and select "View Code" to display its code then add the following method:
                   [C#]
                
                   private string GetDataString(byte[] data)
                   {
                      string result = string.Empty;
                      for (int i = 0; i < data.Length; i++)
                         result = result + Convert.ToChar(data[i]).ToString();
                      return result;
                   }
                 
    
                   [Visual Basic]
                
                   Private Function GetDataString(ByVal data As Byte()) As String
                      Dim result As String = String.Empty
                      Dim i As Integer = 0
                      Do While i < data.Length
                         result = result & Convert.ToChar(data(i)).ToString()
                         i += 1
                      Loop
                      Return result
                   End Function
                 
    
  13. Add a handler to the Completed event of the workflow then add the following code to it:
                   [C#]
                
                   if (barcodeReadActivity1.BarcodeData.Count > 0)
                   {
                      for (int i = 0; i < barcodeReadActivity1.BarcodeData.Count; i++)
                         Console.WriteLine(GetDataString(barcodeReadActivity1.BarcodeData[i].Data));
                   }
                   else
                      Console.WriteLine("No barcodes were recognized.");
                 
    
                   [Visual Basic]
                 
    If barcodeReadActivity1.BarcodeData.Count > 0 Then Dim i As Integer = 0 Do While i < barcodeReadActivity1.BarcodeData.Count Console.WriteLine(GetDataString(barcodeReadActivity1.BarcodeData(i).Data)) i += 1 Loop Else Console.WriteLine("No barcodes were recognized.") End If
  14. Set the output folder of the project .exe to where LEADTOOLS .Net DLLs are installed. For example: <LEADTOOLS_INSTALLDIR>\Bin\Dotnet\Win32
  15. Build, and Run the program to test it.

 

 


Products | Support | Contact Us | Copyright Notices

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