[英]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());
}
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.