Xamarin - 以表格形式显示QR码

时间:2017-04-20 01:06:02

标签: c# xamarin xamarin.forms qr-code

我正在Xamarin编写一个应用程序,为给定的输入创建一个QR代码。

using ZXing.Net.Mobile.Forms;

var writer = new BarcodeWriter
        {
            Format = BarcodeFormat.QR_CODE,
            Options = new EncodingOptions
            {
                Height = 200,
                Width = 600
            }
        };
        var bitmap = writer.Write("Hello Stack Overflow");

我现在如何在表单上显示此条形码?

1 个答案:

答案 0 :(得分:3)

您应该使用 ZXingBarcodeImageView

using System;
using Xamarin.Forms;
using System.Threading.Tasks;
using ZXing.Net.Mobile.Forms;

public class BarcodePage : ContentPage
{
    ZXingBarcodeImageView barcode;

    public BarcodePage ()
    {
        barcode = new ZXingBarcodeImageView {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
            AutomationId = "zxingBarcodeImageView",
        };
        barcode.BarcodeFormat = ZXing.BarcodeFormat.QR_CODE;
        barcode.BarcodeOptions.Width = 300;
        barcode.BarcodeOptions.Height = 300;
        barcode.BarcodeOptions.Margin = 10;
        barcode.BarcodeValue = "Hello Stack Overflow";

        Content = barcode;
    }
}
  

您可以在Github https://github.com/Redth/ZXing.Net.Mobile/blob/master/Samples/Forms/Core/BarcodePage.cs

中查看完整示例