Click here to Skip to main content
16,018,818 members
Articles / Mobile Apps / iOS
Article

Multi-Platform Barcode with LEADTOOLS 18

1 May 2013CPOL2 min read 25K   4  
Multi-Platform Barcode with LEADTOOLS 18

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.

Introduction

LEADTOOLS Version 18, also known as LEADTOOLS Anywhere™, provides the most comprehensive and highest quality imaging SDK technology on the widest variety of development platforms including WinRT, Windows Phone, HTML5, iOS, OS X, Android and Linux. Viewers, annotations and markups, barcode, OCR, PDF, image formats, compression, image processing and more are just a sampling of what LEADTOOLS has to offer any developer, not just those targeting Windows.

Programmers using LEADTOOLS can experience a set of libraries that closely resemble each other on every development platform. This is a distinct advantage for developers whose goal is to create native versions of their apps on multiple platforms. Even if your plan is to develop for a single platform, LEADTOOLS provides a programmer friendly interface for every major platform out there, giving developers the flexibility and peace of mind to easily expand in the future.

Key Features in LEADTOOLS Anywhere™ SDKs

  • Image Viewer Controls designed specifically for .NET, HTML5, WinRT, Windows Phone, iOS, OS X and Android
  • Load, convert and save more than 150 image formats
    • Advanced bit depth, color space and compression support for common formats including PDF, PDF/A, JPEG, JPEG 2000, TIFF, JBIG2 and more
  • Barcode reading and writing for QR, PDF417, Data Matrix, UPC/EAN and more
  • OCR to convert images to searchable text, PDF and DOC
  • Comprehensive Annotation and Markup including geometric shapes, sticky note, redact, highlight and rubber stamp
  • Over 200 Image processing functions for enhancing, correcting and manipulating images

Reading Barcodes on Each Platform

In the examples that follow, we’ll show how to convert a platform-native image into a LEADTOOLS RasterImage, and then use the Barcode engine to get its symbology (i.e. UPC/EAN, Code 128, QR Code, Data Matrix, etc.), location and encoded value. Alternatively, developers can use the RasterCodecs object to load and save their images. However, using LEAD’s conversion utilities is a powerful asset for existing applications because it requires minimal changes to your current code base.

.NET

C#
System.Drawing.Bitmap bitmap = ... // 
// Get a LEADTOOLS RasterImage from the platform image
RasterImage rasterImage = RasterImageConverter.FromImage(bitmap);
// Create a LEADTOOLS Barcode Engine instance
private BarcodeEngine barcodeEngine = new BarcodeEngine();
// Read the first barcode found in the image
BarcodeData barcodeData = barcodeEngine.Reader.ReadBarcode(rasterImage, 
   LogicalRectangle.Empty, BarcodeSymbology.Unknown);
// For this example, simply output the barcode type, location and data in the console
if (barcodeData != null) {
   Console.WriteLine("Symbology:{0}", barcodeData.Symbology);
   Console.WriteLine("Location:{0},{1},{2},{3}", barcodeData.Bounds.X, 
      barcodeData.Bounds.Y, barcodeData.Bounds.Width, barcodeData.Bounds.Height);
   Console.WriteLine("Value:{0}", barcodeData.Value);
} else {
   Console.WriteLine("No barcodes found");
}

Image 1

WinRT & Windows Phone

C#
Windows.UI.Xaml.Media.ImageSource imageSource = ... //
// Get a LEADTOOLS RasterImage from the platform image
RasterImage rasterImage = RasterImageConverter.ConvertFromImageSource(
   imageSource, ConvertFromImageOptions.None);
// Create a LEADTOOLS Barcode Engine instance
private BarcodeEngine barcodeEngine = new BarcodeEngine();
// Read the first barcode found in the image
BarcodeData barcodeData = barcodeEngine.Reader.ReadBarcode(rasterImage, 
   LogicalRectangle.Empty, BarcodeSymbology.Unknown);
// For this example, simply output the barcode type, location and data in the console
if (barcodeData != null) {
   Console.WriteLine("Symbology:{0}", barcodeData.Symbology);
   Console.WriteLine("Location:{0},{1},{2},{3}", barcodeData.Bounds.X, 
      barcodeData.Bounds.Y, barcodeData.Bounds.Width, barcodeData.Bounds.Height);
   Console.WriteLine("Value:{0}", barcodeData.Value);
} else {
   Console.WriteLine("No barcodes found");
}

Image 2

iOS & OS X

Objective-C
UIImage* uiImage = ... //
// Get a LEADTOOLS RasterImage from the platform image
LTRasterImage* rasterImage = [LTRasterImageConverter convertFromImage:uiImage
   options:LTConvertFromImageOptions_None error:nil];
// Create a LEADTOOLS Barcode Engine instance
LTBarcodeEngine* barcodeEngine = [LTBarcodeEngine new];
// Read the first barcode found in the image
LTBarcodeData* barcodeData = [barcodeEngine.reader readBarcode:rasterImage
   searchBounds:LeadRect_Empty() symbologies:nil symbologiesCount:0 error:nil];
// For this example, simply retrieve the barcode type, location and data
if(barcodeData != nil) {
   NSLog(@"Symbology:%u", barcodeData.symbology);
   NSLog(@"Location:%u,%u,%u,%u", barcodeData.bounds.x, barcodeData.bounds.y, 
      barcodeData.bounds.width, barcodeData.bounds.height);
   NSLog(@"Value:%@", barcodeData.value);
} else {
  NSLog(@"No barcodes found");
}

 Image 3

Android

C++
android.graphics.Bitmap bitmap = ... //
// Get a LEADTOOLS RasterImage from the platform image
RasterImage rasterImage = RasterImageConverter.convertFromBitmap(
   bitmap, ConvertFromImageOptions.NONE);
// Create a LEADTOOLS Barcode Engine instance
private BarcodeEngine barcodeEngine = new BarcodeEngine();
// Read the first barcode found in the image
BarcodeData barcodeData = barcodeEngine.getReader().readBarcode(
   rasterImage, LeadRect.getEmpty(), BarcodeSymbology.UNKNOWN);
// For this example, simply output the barcode type, location and data in the console
if (barcodeData != null) {
   Log.i("LEADTOOLS.BarcodeDemo", String.format("Symbology:%s", barcodeData.getSymbology()));
   Log.i("LEADTOOLS.BarcodeDemo", String.format("Location:%1$s,%2$s,%3$s,%4$s", 
      barcodeData.getBounds().getX(), barcodeData.getBounds().getY(), 
      barcodeData.getBounds().getWidth(), barcodeData.getBounds().getHeight()));
   Log.i("LEADTOOLS.BarcodeDemo", String.format("Value:%s", barcodeData.getValue()));
} else {
   Log.i("LEADTOOLS.BarcodeDemo", "No barcodes found");
}

 Image 4

Download the Full Examples

You can download fully functional demos which includes the features discussed above. To run these examples 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)


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 sales@leadtools.com or support@leadtools.com.
This is a Organisation (No members)


Comments and Discussions

 
-- There are no messages in this forum --