Xamarin - 在表单中显示二维码

Xamarin - Display QR code in form

我正在 Xamarin 中编写一个应用程序来为给定的输入创建二维码。

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");

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

你应该使用 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;
    }
}

You can check the full sample in Github https://github.com/Redth/ZXing.Net.Mobile/blob/master/Samples/Forms/Core/BarcodePage.cs