Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

QR Code generator

$
0
0

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
                        }
                    })

                }
            };
        }
    }
}

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>