【问题标题】:Xamarin - Display QR code in formXamarin - 在表单中显示二维码
【发布时间】:2017-04-20 01:06:01
【问题描述】:

我正在 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");

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

【问题讨论】:

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


    【解决方案1】:

    你应该使用 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查看完整示例

    【讨论】:

    • 很棒的开源项目 :) @BarneyChambers
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多