Click here to Skip to main content
Full site     10M members (29.2K online)    

Multi-Platform Barcode with LEADTOOLS 18

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

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

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

WinRT & Windows Phone

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

iOS & OS X

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

 

Android

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

 

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.

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search 
Per page   
-- There are no messages in this forum --

Last Updated 1 May 2013 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2013