Click here to Skip to main content
12,765,284 members (36,124 online)
Click here to Skip to main content


20 bookmarked
Posted 7 Nov 2011

How to Read Barcodes from Images using LEADTOOLS

, 7 Jan 2013 CPOL
In this article, we will create a simple application that loads an image and reads its barcodes. Try it out for yourself by downloading a fully functional evaluation SDK from the links provided below the tutorial.

Editorial Note

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Leadtools;
using Leadtools.Barcode;
using Leadtools.Codecs;
using Leadtools.Forms;

namespace LEADTOOLSBarcodeTutorial
   public partial class Form1 : Form
      public Form1()
         /* Uncomment this and add your license file and developer key
         //string licenseFilePath = "Replace this with the path to the LEADTOOLS license file";
         //string developerKey = "Replace this with your developer key";
         //RasterSupport.SetLicense(licenseFilePath, developerKey); */


      private void btnLoad_Click(object sender, EventArgs e)
         using (OpenFileDialog ofd = new OpenFileDialog())
            ofd.Filter = "TIFF|*.tif|JPEG|*.jpg|PNG|*.png|BMP|*.bmp|All Files|*.*";
            if (ofd.ShowDialog() == DialogResult.OK)
               using (RasterCodecs codecs = new RasterCodecs())
                  // Load first page into the viewer
                  rasterImageViewer1.Image = codecs.Load(ofd.FileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);

      private void btnRead_Click(object sender, EventArgs e)
         // Create a Barcode engine
         BarcodeEngine engine = new BarcodeEngine();

         // Ignore errors in case there are corrupted ones on the image.
         engine.Reader.ErrorMode = BarcodeReaderErrorMode.IgnoreAll;

         // Read all barcodes with default options. For a tutorial on how to change the options, for example, read barcodes in both horizontal and vertical directions
         // see
         BarcodeData[] barcodes = engine.Reader.ReadBarcodes(rasterImageViewer1.Image, LogicalRectangle.Empty, 0, null);

         // Print out the barcodes we found
         StringBuilder results = new StringBuilder();
         results.AppendFormat("{0} barcodes found.\r\n\r\n", barcodes.Length);
         for (int i = 0; i < barcodes.Length; i++)
            BarcodeData barcode = barcodes[i];
            results.AppendFormat("  {0} - {1} - {2}\r\n", i + 1, barcode.Symbology, barcode.Value);

         txtResults.Text = results.ToString();

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Help desk / Support LEAD Technologies, Inc.
United States United States
Since 1990, LEAD has established itself as the world's leading provider of software development toolkits for document, medical, multimedia, raster and vector imaging. LEAD's flagship product, LEADTOOLS, holds the top position in every major country throughout the world and boasts a healthy, diverse customer base and strong list of corporate partners including some of the largest and most influential organizations from around the globe. For more information, contact or
Group type: Organisation (No members)

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 7 Jan 2013
Article Copyright 2011 by LEADTOOLS Support
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid