Generate QR code with Xamarin.Forms and Zxing

前端 未结 2 752
小鲜肉
小鲜肉 2021-02-14 09:31

I\'ve seen alot about this online (old posts) but nothing seems to work for me. I\'m trying to generate a QR code out of a string and display it in the app.

Here\'s what

2条回答
  •  独厮守ぢ
    2021-02-14 09:57

    It seems to be a known issue.
    Luckily there is a workaround, to set a HeightRequest & WidthRequest, here is a working code example:

    ZXingBarcodeImageView GenerateQR(string codeValue)
    {
        var qrCode = new ZXingBarcodeImageView
        {
            BarcodeFormat = BarcodeFormat.QR_CODE,
            BarcodeOptions = new QrCodeEncodingOptions
            {
                Height = 350,
                Width = 350
            },
            BarcodeValue = codeValue,
            VerticalOptions = LayoutOptions.CenterAndExpand,
            HorizontalOptions = LayoutOptions.CenterAndExpand
        };
        // Workaround for iOS
        qrCode.WidthRequest = 350;
        qrCode.HeightRequest = 350;
        return qrCode;
    }
    

提交回复
热议问题