Click here to Skip to main content
15,882,376 members
Articles / Product Showcase

How to Read Barcodes from Images using LEADTOOLS

7 Jan 2013CPOL3 min read 57.7K   2.3K   25   3
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.

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.


Barcodes have a very prevalent role in today’s world.  From retail stores to mobile devices, hundreds of varieties of barcodes are in use day to day.  LEADTOOLS supports reading and writing nearly every barcode symbology and can be used in C++, .Net, Silverlight and Windows Phone.  Its high level programming interfaces can read and write barcodes in just a few lines of code.

On top of its expansive barcode support, LEADTOOLS is indispensible for image-based barcode applications because of its myriad of additional imaging technology including document cleanup, forms recognition and processing, OCR, TWAIN scanning, and support for over 150 formats.

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. 

Key Barcode Features in LEADTOOLS SDKs

  • Detect, Read and Write 1D and 2D Barcodes such as UPC, EAN, Code 128, Data Matrix, QR Code, PDF417
  • High level, programmer friendly .NET interface
    • Detect and read all barcode types with a single function call
    • Configuration options to read only barcodes of a certain type, color, granularity, orientation, region of interest and more
    • Automated image cleanup for 2D barcodes - ideal for poor quality faxes and scanned documents
  • Load, save and convert over 150 formats including JPEG, JPEG2000, TIFF, FAX, CMP & many more
  • Document Cleanup
  • Fast TWAIN and WIA image capture
  • High level image display controls for .NET, WPF & ASP.NET

Additional features include:

  • PDF Read/Write/Edit
  • Forms Recognition and Processing
  • Annotation and Markup
  • Medical 3D Volume Reconstruction
  • Multimedia codecs and processing
  • MPEG-2 Transport Stream


This example requires Visual Studio 2008 or later and LEADTOOLS’ .NET 2.0 libraries.  Support for .NET 4.0 and Silverlight are also available.

Using the Barcode SDK

First, load an image with the RasterCodecs object.  This class handles all of the file I/O and image metadata features.  You may notice some of the references for individual codec files such as Leadtools.Codecs.Tif.dll, Leadtools.Codecs.Bmp.dll, etc.  These libraries add support for those file formats, so if you desire to load any additional files you will need to add a reference to the appropriate codec or you will get an “Invalid File Format” error.

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);

Next, read the barcodes with the BarcodeEngine object.  This example uses the default options to read all barcodes horizontally oriented barcodes.  Additional options exist for narrowing the search area, barcode type and barcode direction.

// 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.
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, 

When running the sample, the image will be displayed in the viewer and all of the detected barcodes written in the textbox:



LEADTOOLS provides developers with access to the world’s best performing and most stable imaging libraries in an easy-to-use, high-level programming interface enabling rapid development of business-critical applications. 

Barcode is only one of the many technologies LEADTOOLS has to offer.  For more information on our other products, be sure to visit our home page, download a free fully functioning evaluation SDK, and take advantage of our free technical support during your evaluation.

Download the Barcode Example

You can download a fully functional demo which includes the features discussed above.  To run this example you will need the following:


Need help getting this sample up and going?  Contact our support team for free technical support!  For pricing or licensing questions, you can contact our sales team ( or call us at 704-332-5532.


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

Written By
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
This is a Organisation (No members)

Comments and Discussions

QuestionPDF Support Pin
jsergeant20-Aug-13 15:37
jsergeant20-Aug-13 15:37 
AnswerRe: PDF Support Pin
LEADTOOLS Support21-Aug-13 4:48
sponsorLEADTOOLS Support21-Aug-13 4:48 
QuestionGreat barcode toolkit Pin
Robert Kon19-Nov-12 21:20
Robert Kon19-Nov-12 21:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.