简体   繁体   English

如何在 UWP 应用程序中生成二维码?

[英]How can I generate QR code in UWP application?

I have tried to install QrCode.net nugget package for an UWP application, but it writes the error for me:我曾尝试为 UWP 应用程序安装 QrCode.net nugget 包,但它为我写了错误:

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 应用程序的任何 nugget 包可以帮助我创建和显示从字符串生成的 QR 码? (UWP/C#) (UWP/C#)

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 应用程序的任何 nugget 包可以帮助我创建和显示从字符串生成的 QR 码? (UWP/C#) (UWP/C#)

Since you are developing an UWP app, you can use the Zxing.Net.Mobile package.由于您正在开发 UWP 应用程序,因此您可以使用Zxing.Net.Mobile包。 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;
}

This is how you do using the MVVM pattern ( based on Grace Feng's approach )这就是您如何使用MVVM 模式基于 Grace Feng 的方法

XAML 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());
}

2020 Answer 2020 答案

Another option is to use QRCoder.另一种选择是使用 QRCoder。 Some example setup from the github .来自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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用QrCode.net库生成QR码且周围没有空格? - How can I generate a QR code without white space around it using the QrCode.net library? 如何在 UWP 中对齐我通过代码生成的元素? - How do i align an Element in UWP that i generate through code? 如何使用.net 3.5在Visual Studio 2008,asp.net Web应用程序中生成QR码? - How to generate QR code in visual studio 2008,asp.net web application using .net 3.5? 如何获取 Windows UWP ClaimedBarcodeScanner 识别的二维码的像素坐标 - How to obtain the pixel coordinates of a QR code recognized by the Windows UWP ClaimedBarcodeScanner 如何在手机摄像头中读取QR码? - How can I read QR code in my phone camera? 如何使用Xamarin Android扫描QR码 - How can I scan QR code with xamarin android 我有一个用 C# 编写的 Qr 生成器应用程序。 所以现在我想生成在运行时每 10 秒改变一次的 Qr 代码 - I have a Qr generator application written in C#. So now i want to generate Qr Code that willl change in every 10 seconds during runtime 如何访问UWP中的当前应用程序文件夹? - How can I access the current application folder in UWP? 如何在 UWP 或 WPF 应用程序中显示自定义警报? - How can I show custom alerts in UWP or WPF application? QR码扫描在UWP中不起作用 - QR code scanning does not work in UWP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM