Live Capture Barcode Reading

Take the following steps to easily add to your Xamarin application an additional feature: Live capture barcode reading.

  1. Create a new Xamarin forms project and add the camera control by following the Adding a Basic Xamarin Camera Control tutorial.

  2. Right-click the Solution in Visual Studio and select Manage NuGet packages for Solution. Type a search for "Leadtools.Barcode" to install/add it to your solution.

  3. Once you have added the Leadtools.Barcode Nuget Package, add the following global variable to the MainPage:

    C#
    Leadtools.Barcode.BarcodeEngine barcodeEngine; 

  4. In the MainPage constructor, after the license code and the InitializeComponent(), initialize the BarcodeEngine object, set the AutoRotateImage option of the Camera, and subscribe to the FrameReceived event:

    C#
    barcodeEngine = new Leadtools.Barcode.BarcodeEngine(); 
    leadCamera.CameraOptions.AutoRotateImage = true; 
    leadCamera.FrameReceived += LeadCamera_FrameReceived; 

  5. Add the FrameReceived event:

    C#
    private void LeadCamera_FrameReceived(Leadtools.Camera.Xamarin.FrameHandlerEventArgs e) 
    { 
       if (e.Image != null) 
       { 
          var data = barcodeEngine.Reader.ReadBarcode(e.Image, Leadtools.LeadRect.Empty, Leadtools.Barcode.BarcodeSymbology.Unknown); 
     
          if (data != null && data.Value != null) 
          { 
             Device.BeginInvokeOnMainThread(() => 
             { 
                DisplayAlert("Barcode Found!", $"{data.Symbology} : {data.Value}", "OK"); 
             }); 
          } 
       } 
    } 

  6. After completing the previous steps, you can build and run the project and deploy it to your device and start scanning barcodes.
Help Version 22.0.2021.10.25
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2022 LEAD Technologies, Inc. All Rights Reserved.
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2022 LEAD Technologies, Inc. All Rights Reserved.