LEADTOOLS v18(即LEADTOOLS Anywhere)将其世界领先的成像技术扩展到了WinRT、iOS、Android、Windows Phone和Linux等平台。不仅如此,用户还可以在所有流行平台中实现查看、注释和标记、OCR、条形码、PDF、图像格式、压缩和图像处理等功能。
LEADTOOLS在每个开发平台上面都提供了一组非常相似的开发库,这是LEADTOOLS的一个非常明显的优势,让开发者既能够开发原生的应用程序,又不用花费太多的时间进行完全的代码重写。
接下来,我们就一起展示一下LEADTOOLS Anywhere如何在每个平台上面读取条形码。
.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"); }