Articles in this section
Category / Section

How to capture and scan the Barcode in Xamarin.Forms?

4 mins read

ZXing (zebra crossing) is an open-source tool to decode barcodes. It allows users to scan most of the 1D and 2D barcodes, including QR and DataMatrix Barcodes.

 

 

Barcode image in android

 

Getting Started

 

ZXing.Net Mobile is available for Xamarin applications as both a component and a NuGet package that can be installed in iOS, Android and Windows projects. Need to add the package or Nuget to all of the projects in Xamarin applications to get started.

 

Please find the following steps:

 

1. Right click the project and select Manage NuGet Packages.

2. Browse packages from source(“https://www.nuget.org/api/v2”) and add the ZXing.Net.Mobile packages in all of the projects in Xamarin applications.

 

 

Create a Scanner Page

 

ZXing.Net.Mobile is a C#/.NET library based on the open source Barcode Library: ZXing (Zebra Crossing). It works with Xamarin.iOS, Xamarin.Android and Windows Universal. The goal of ZXing.Net.Mobile is to make scanning barcodes in our own Xamarin application.

 

Create a new ZXingScannerPage and then push the page onto the navigation stack using below code snippet,

ZXingScannerPage scanPage = new ZXingScannerPage ();
await Navigation.PushAsync (scanPage);

 

 

Validating Output

 

The text and type of the Barcode can be displayed when the OnScanResult event is fired using below code snippet,

scanPage.OnScanResult += (result) => 
{
         scanPage.IsScanning = false;
         ZXing.BarcodeFormat barcodeFormat = result.BarcodeFormat;
         string type = barcodeFormat.ToString();
         Device.BeginInvokeOnMainThread(() => 
         {
                    Navigation.PopAsync();
                    DisplayAlert("The Barcode type is : " + type, "The text is : " + result.Text, "OK");
         });
};

 

Please find the sample from the below link,

https://www.syncfusion.com/downloads/support/directtrac/general/ze/Syncfusion_Barcode_Scanner68333879

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied