Forum Xamarin.Forms

QR Code generator

Programmer_00Programmer_00 ZAMember ✭✭
edited August 2017 in Xamarin.Forms

I've been trying to generate a QR Code based on input value. I am using Acr.BarCodes but upon entering a value, the actual QR code image doesn't display.
Any help as to why this is happening will be appreciated, thanks. :)
The class:
public class GeneratorPage : ContentPage
{
public GeneratorPage()
{
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");
                }
            };
            this.Content = new StackLayout
            {
                Children = {
                    new Label {
                        Text="QR CODE GENERATOR",
                        FontSize=25,
                        FontAttributes=FontAttributes.Bold,
                        HorizontalOptions=LayoutOptions.CenterAndExpand,
                    },
                    btnCreateQR,
                    imgCode,
                    new TableView(new TableRoot {
                        new TableSection {
                            txtBarcode
                        }
                    })

                }
            };
        }
    }
}

Answers

Sign In or Register to comment.