2

I have tried to install QrCode.net nugget package for an UWP application, but it writes the error for me:

using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

are not not exists.

Does anyone know any nugget package for UWP application that helps me to create and show a QR code that generated from a string? (UWP/C#)

3 Answers 3

6

Does anyone know any nugget package for UWP application that helps me to create and show a QR code that generated from a string? (UWP/C#)

Since you are developing an UWP app, you can use the Zxing.Net.Mobile package. After installed this package, to generate a barcode, you can refer to the following example:

<Image x:Name="qrcodeImg" Stretch="None" />

code behind:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    var write = new BarcodeWriter();
    write.Format = ZXing.BarcodeFormat.QR_CODE;
    var wb = write.Write("BarCode Content");
    this.qrcodeImg.Source = wb;
}
Sign up to request clarification or add additional context in comments.

3 Comments

I did try this approach but at last line I did get error Cannot implicitly convert type 'byte[]' to 'Windows.UI.Xaml.Media.ImageSource'
You should probably cast it 'var wb = (write as ZXing.BarcodeWriterGeneric<WriteableBitmap>).Write(jsonItem);'
System.Drawing is not available in UWP (anymore?), the library is not updated and some of the code requires System.Drawing.Bitmap to be available.
0

This is how you do using the MVVM pattern (based on Grace Feng's approach)

XAML

<Image Source="{Binding QRImage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

Viewmodel

// Property
public WriteableBitmap QRImage { get; set; }

// Function to call
private void SetQR()
{
    var options = new QrCodeEncodingOptions()
    {
        DisableECI = true,
        CharacterSet = "UTF-8",
        Width = 1000,
        Height = 1000
    };

    BarcodeWriter writer = new BarcodeWriter();
    writer.Format = BarcodeFormat.QR_CODE;
    writer.Options = options;
    QRImage= writer.Write(SelectedEvent.GetQrString());
}

Comments

0

2020 Answer

Another option is to use QRCoder. Some example setup from the github.

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);

1 Comment

ZXing.Net is actively maintained, take a look at github (github.com/micjahn/ZXing.Net) and nuget (nuget.org/packages/ZXing.Net). A new version is on the way. Sometimes it is better to take a look at the original pages instead of a blog post from 2017.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.