Click here to Skip to main content
Click here to Skip to main content

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 reviews are intended to provide you with information on products and services that we consider useful and of value to developers.

Introduction

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
  • OCR, MICR & OMR
  • Forms Recognition and Processing
  • Annotation and Markup
  • DICOM & PACS
  • Medical 3D Volume Reconstruction
  • Multimedia codecs and processing
  • MPEG-2 Transport Stream

Environment

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, 
       barcode.Value);
}

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

How-to-Read-Barcodes/image001.jpg

Conclusion

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:

Support

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 (sales@leadtools.com) or call us at 704-332-5532.

License

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

Share

About the Author

LEADTOOLS Support
Help desk / Support LEAD Technologies, Inc.
United States United States
With a rich history of over twenty years, 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 sales@leadtools.com or support@leadtools.com.
Group type: Organisation (No members)


Follow on   Twitter   Google+

Comments and Discussions

 
QuestionPDF Support Pinmemberjsergeant20-Aug-13 16:37 
AnswerRe: PDF Support PingroupLEADTOOLS Support21-Aug-13 5:48 
QuestionGreat barcode toolkit PinmemberRobert Kon19-Nov-12 22:20 

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

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

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