Take the following steps to start a project:
Start Visual Studio .NET.
Choose File->New->Project... from the menu.
In the New Project dialog box, Choose either "Visual C# Projects" or "VB Projects" in the Projects Type List, and choose "Windows Application" (or "Windows Forms Application" in Visual Studio 2010) in the Templates List.
Type the project name as "ReadingBarcodes" 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.
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 and browse to the "C:\LEADTOOLS 19\Bin\DotNet\Win32" folder (or "C:\LEADTOOLS 19\Bin\DotNet4\Win32" if you are going to use .NET 4) and select the following DLLs:
Click the Select button and then press the OK button to add the above DLLs to the application.
Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file:
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.FormsImports Leadtools.Barcode
using Leadtools;using Leadtools.Codecs;using Leadtools.Forms;using Leadtools.Barcode;
Drag and drop two buttons in Form1. Change the following properties:
| Property | Value | 
|---|---|
| Name | loadImageButton | 
| Text | Load image | 
| Name | readBarcodesButton | 
| Text | Read barcodes | 
Add the following private variables to Form1
Private barcodeEngineInstance As BarcodeEngine ' The barcode enginePrivate theImage As RasterImage ' The current loaded imagePrivate imageFileName As String ' Last file name we loaded, this is used in the "Writing Barcodes" tutorial
private BarcodeEngine barcodeEngineInstance; // The barcode engineprivate RasterImage theImage; // The current loaded imageprivate string imageFileName; // Last file name we loaded, this is used in the "Writing Barcodes" tutorial
Add the following initialization code to Form1
Protected Overrides Sub OnLoad(ByVal e As EventArgs)' Use the developer and license file by LEADTOOLSDim MY_LICENSE_FILE As String = "d:\temp\TestLic.lic"Dim MY_DEVELOPER_KEY As String = "xyz123abc"RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DEVELOPER_KEY)' Create the BarcodeEngine instancebarcodeEngineInstance = New BarcodeEngine()MyBase.OnLoad(e)End Sub
protected override void OnLoad(EventArgs e){// Replace the keys with unlock support string provided by LEADTOOLS, or use the evaluation kernel// Unlock reading 1D barcodesstring MY_LICENSE_FILE = "d:\\temp\\TestLic.lic";string MY_DEVELOPER_KEY = "xyz123abc";RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DEVELOPER_KEY);// Create the BarcodeEngine instancebarcodeEngineInstance = new BarcodeEngine();base.OnLoad(e);}
Add the following clean up code to Form1
Protected Overrides Sub OnFormClosed(ByVal e As FormClosedEventArgs)' Delete our resourcesIf Not theImage Is Nothing ThentheImage.Dispose()End IfMyBase.OnFormClosed(e)End Sub
protected override void OnFormClosed(FormClosedEventArgs e){// Delete our resourcesif(theImage != null){theImage.Dispose();}base.OnFormClosed(e);}
Add the following code to loadImageButton click procedure:
Private Sub loadImageButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles loadImageButton.ClickDim fileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\Barcode1.tif"' Or comment out the following to load your own file' Using dlg As New OpenFileDialog' If dlg.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then' fileName = dlg.FileName' Else' Return' End If' End Using' Load the imageUsing codecs As New RasterCodecsDim newImage As RasterImage = codecs.Load(fileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)' Delete old image if anyIf Not theImage Is Nothing ThentheImage.Dispose()End IftheImage = newImageimageFileName = fileNameEnd UsingEnd Sub
private void loadImageButton_Click(object sender, EventArgs e){string fileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Barcode1.tif";// Or comment out the following to load your own file//using(OpenFileDialog dlg = new OpenFileDialog())//{// if(dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)// {// fileName = dlg.FileName;// }// else// {// return;// }//}// Load the imageusing(RasterCodecs codecs = new RasterCodecs()){string fileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Barcode1.tif";RasterImage newImage = codecs.Load(fileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);// Delete old image if anyif(theImage != null){theImage.Dispose();}theImage = newImage;imageFileName = fileName;}}
Add the following code to readBarcodesButton click procedure:
Private Sub readBarcodesButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles readBarcodesButton.ClickIf theImage Is NothingMessageBox.Show("Load an image first")ReturnEnd IfTry' Read all the barcodes' The first parameter is the image from which to read the barcodes.' The second parameter is the search rectangle. Pass an empty rectangle to indicate the entire image.' The third parameter is the maximum number of barcodes to read. Pass 0 for all found in the image.' The last parameter is an array of the BarcodeSymbology we are interested in. Pass null (or Nothing)' to indicate that we do not care, and want all available barcodes to be read (found in the image and supported by' the current unlock support mechanism)Dim dataArray() As BarcodeData = barcodeEngineInstance.Reader.ReadBarcodes(theImage, LogicalRectangle.Empty, 0, Nothing)Dim sb As New StringBuilder()sb.AppendFormat("{0} barcode(s) found", dataArray.Length)sb.AppendLine()For i As Integer = 0 To dataArray.Length - 1Dim data As BarcodeData = dataArray(i)sb.AppendFormat("Symbology: {0}, Location: {1}, Data: {2}", data.Symbology.ToString(), data.Bounds.ToString(), data.Value)sb.AppendLine()NextMessageBox.Show(sb.ToString())Catch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd Sub
private void readBarcodesButton_Click(object sender, EventArgs e){if(theImage == null){MessageBox.Show("Load an image first");return;}try{// Read all the barcodes// The first parameter is the image we want to read the barcodes from// The second parameter is the search rectangle. Pass an empty rectangle to indicate the entire image.// The third parameter is the maximum number of barcodes to read. Pass 0 for all barcodes found in the image.// Last parameter is an array of the BarcodeSymbology we are interested in. Pass null (or Nothing)// to indicate that we do not care, and want all barcodes available to be read(that have been found in the image and are supported by// the current unlock support mechanism)BarcodeData[] dataArray = barcodeEngineInstance.Reader.ReadBarcodes(theImage, LogicalRectangle.Empty, 0, null);StringBuilder sb = new StringBuilder();sb.AppendFormat("{0} barcode(s) found", dataArray.Length);sb.AppendLine();for(int i = 0; i < dataArray.Length; i++){BarcodeData data = dataArray[i];sb.AppendFormat("Symbology: {0}, Location: {1}, Data: {2}", data.Symbology.ToString(), data.Bounds.ToString(), data.Value);sb.AppendLine();}MessageBox.Show(sb.ToString());}catch(Exception ex){MessageBox.Show(ex.Message);}}


|   |  | 






Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.