This article shows how to create a barcode scanner in all the three platforms: Android, iOS and Windows using Xamarin.Forms.
In my last article I explained how to create a barcode scanner in Xamarin.Forms. Here I'm going to explain something about a Barcode \ QR Code Generator.
For creating the QR Code Generator I'm going to use the same NuGet package, Arc.Barcodes, a cross-platform creator built on top of ZXing.Net.Mobile to allow for easy cross-platform access from Shared/PCL core libraries that I have used to create the Barcode Scanner.
Now we want to initialize the corresponding NuGet package in each platform-specific startup classes.
In Android, on MainActivity.cs call:
global::Acr.BarCodes.BarCodes.Init(() => (Activity)Xamarin.Forms.Forms.Context); before calling LoadApplication();.
In iOS, on AppDelegate.cs call global::Xamarin.Forms.Forms.Init(); before calling LoadApplication();.
In Windows Phone, on MainPage.cs call global::Xamarin.Forms.Forms.Init(); before calling LoadApplication();.
Now we can create a button to initialize the event and Image View to load the QR Code and most importantly we must add an entry that will carry the value that will be carried by the QR Code.
- var btnCreateQR = new Button { Text = "Genrate" };
- var imgCode = new Image();
- var txtBarcode = new EntryCell { Label = "Value " };
- btnCreateQR.Clicked += (sender, e) =>
- {
- try
- {
- var QRstream = BarCodes.Instance.Create(new BarCodeCreateConfiguration
- {
- Format = BarCodeFormat.QR_CODE,
- BarCode = txtBarcode.Text.Trim(),
- Width = 200,
- Height = 200
- }
- );
- txtBarcode.LabelColor = Color.White;
- imgCode.Source = ImageSource.FromStream(() => QRstream );
- }
- catch (Exception ex)
- {
- txtBarcode.LabelColor = Color.Red;
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- DisplayAlert("Alert", "Enter value that want to be carried in the QR Code", "OK");
- }
- };


You can refer to the sample project attached with this for more details. Also, you can generate a Barcode, Data Matrix, Maxi code and so on, using the same logic.


Sajid HussainPosted Dec 20, 2017, 7:27 PM EST
I want that one application start qr screen start, without any button click?after reading qr code its again start for next scan? how can i get this?
Joginder BangerPosted Mar 25, 2016, 12:59 PM EDT
Hello sir ..i download your project successfully but i trying to open these are project no load ..IOS...Android and microsoft...what i do for right.
Vaikesh K PPosted Aug 13, 2015, 1:16 AM EDT
Thanks Gowtham Rajamanickam :)
Vaikesh K PPosted Aug 13, 2015, 1:15 AM EDT
Thanks Sibeesh Venu
Gowtham RajamanickamTOP 100Posted Aug 13, 2015, 12:50 AM EDT
good one..
Sibeesh VenuTOP 100Posted Aug 13, 2015, 12:29 AM EDT
Nice Share :)
Vaikesh K PPosted Aug 12, 2015, 8:51 PM EDT
Thanks Santhakumar Munuswamy :)
Santhakumar MunuswamyPosted Aug 12, 2015, 10:53 AM EDT
Good Article. Thanks for sharing
Vaikesh K PPosted Aug 12, 2015, 4:55 AM EDT
Thanks Ankit Bansal...
Ankit BansalPosted Aug 12, 2015, 4:53 AM EDT
good one...
Vaikesh K PPosted Aug 12, 2015, 3:41 AM EDT
Thanks Gopi Chand sir :)
Gopi ChandPosted Aug 12, 2015, 3:38 AM EDT
Very useful...well done Vaikesh
Vaikesh K PPosted Aug 12, 2015, 2:21 AM EDT
Thanks Rajeesh Menoth Sir :)
Rajeesh MenothPosted Aug 12, 2015, 1:55 AM EDT
Good One
Vaikesh K PPosted Aug 12, 2015, 1:40 AM EDT
Thanks Karthikeyan K :)
Karthikeyan KPosted Aug 12, 2015, 1:29 AM EDT
Nice one...Thanks for share