我试图使用这里提供的说明在我的WPF应用程序中添加QR码生成器:https://www.kailashsblogs.com/2020/05/generate-qr-code-in-wpf.html?m=0&fbclid=IwAR0CMMRGwE1eH-ASW4jVzML1oyEszLeSWAosK2QfuwOKCot_665O2aR1tEA
我安装了中兴。但是在将代码复制到我的MainWindow.xaml.cs后,我得到了错误“使用泛型类型'barcodereader'需要1个类型参数”
private void BtnConvert_Click(object sender, RoutedEventArgs e)
{
try
{
System.Drawing.Image img = null;
BitmapImage bimg = new BitmapImage();
using (var ms = new MemoryStream())
{
BarcodeWriter writer; <- HERE
writer = new ZXing.BarcodeWriter() { Format = BarcodeFormat.QR_CODE }; <-HERE
writer.Options.Height = 80;
writer.Options.Width = 280;
writer.Options.PureBarcode = true;
img = writer.Write(this.txtbarcodecontent.Text);
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
bimg.BeginInit();
bimg.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
bimg.CacheOption = BitmapCacheOption.OnLoad;
bimg.UriSource = null;
bimg.StreamSource = ms;
bimg.EndInit();
this.imgbarcode.Source = bimg;// return File(ms.ToArray(), "image/jpeg");
this.tbkbarcodecontent.Text = this.txtbarcodecontent.Text;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.IO;
using ZXing;
using System.Drawing;
我该怎么修理它?
1条答案
按热度按时间6rqinv9w1#
如果你使用ZXing.Net和.Net Core / .Net Standard,你必须使用不同的绑定包之一。它们包含不同图像库的特定BarcodeReader和BarcodeWriter实现。https://www.nuget.org/packages?q=zxing.bindings这是设计的,因为.Net核心包中不包括位图实现。
例如,添加包https://www.nuget.org/packages/ZXing.Net.Bindings.Windows.Compatibility并更改行writer = new ZXing.BarcodeWriter(){ Format = BarcodeFormat.QR_CODE }; to writer = new ZXing.Windows.Compatibility.BarcodeWriter(){ Format = BarcodeFormat.QR_CODE };