In This Topic
Example: Here is an example that shows how to read barcodes from Android.Graphics.Bitmap object in Xamarin.Android.
// The project, which uses this code, must have references to the following assemblies:
// - Vintasoft.XamarinBarcode.Android
/// <summary>
/// Reads barcodes from an image.
/// </summary>
/// <param name="barcodeImage">An image with barcodes.</param>
public static void ReadBarcodesFromBitmap(Android.Graphics.Bitmap barcodeImage)
{
// create barcode reader
using (Vintasoft.XamarinBarcode.BarcodeReader reader = new Vintasoft.XamarinBarcode.BarcodeReader())
{
// specify that reader must search for Code39, Code39Extended,
// Code128, SSCC18 and DataMatrix barcodes
reader.Settings.ScanBarcodeTypes =
Vintasoft.XamarinBarcode.BarcodeType.Code39 |
Vintasoft.XamarinBarcode.BarcodeType.Code128 |
Vintasoft.XamarinBarcode.BarcodeType.DataMatrix;
reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.XamarinBarcode.SymbologySubsets.BarcodeSymbologySubsets.Code39Extended);
reader.Settings.ScanBarcodeSubsets.Add(Vintasoft.XamarinBarcode.SymbologySubsets.BarcodeSymbologySubsets.SSCC18);
// specify that reader must search for horizontal and vertical barcodes only
reader.Settings.ScanDirection = Vintasoft.XamarinBarcode.ScanDirection.Horizontal | Vintasoft.XamarinBarcode.ScanDirection.Vertical;
// use Automatic Recognition
reader.Settings.AutomaticRecognition = true;
// read barcodes from image
Vintasoft.XamarinBarcode.IBarcodeInfo[] infos = reader.ReadBarcodes(barcodeImage);
// if barcodes are not detected
if (infos.Length == 0)
{
Console.WriteLine("No barcodes found.");
}
// if barcodes are detected
else
{
// get information about extracted barcodes
Console.WriteLine(string.Format("{0} barcodes found:", infos.Length));
Console.WriteLine();
for (int i = 0; i < infos.Length; i++)
{
Vintasoft.XamarinBarcode.IBarcodeInfo info = infos[i];
Console.WriteLine(string.Format("[{0}:{1}]", i + 1, info.BarcodeType));
Console.WriteLine(string.Format("Value: {0}", info.Value));
Console.WriteLine(string.Format("Region: {0}", info.Region));
Console.WriteLine();
}
}
}
}