[英]ZXing - Using the generic type BarcodeWriter<TOutput> requires 1 type argument ZXing.NET.Mobile
I have been trying to generate a QRCode using ZXing.Net.Mobile and ZXing.Net.Mobile.Forms: https://github.com/Redth/ZXing.Net.Mobile and have come across the following error:我一直在尝试使用 ZXing.Net.Mobile 和 ZXing.Net.Mobile.Forms: https://github.com/Redth/ZXing.Net.Mobile生成 QRCode 并遇到以下错误:
"Severity Code Description Project File Line Suppression State Error CS0305 Using the generic type 'BarcodeWriter' requires 1 type arguments TestApp.Android G:\Tests\TestApp\TestApp\TestApp.Android\SelectedBookingPage.cs 70 Active " “严重性代码描述项目文件行抑制 State 错误 CS0305 使用通用类型‘BarcodeWriter’需要 1 类型 arguments TestApp.Android G:\Tests\TestApp\TestApp\TestApp.Android\SelectedBookingPage.cs 70 Active”
This is my code:这是我的代码:
BarcodeWriter writer = new BarcodeWriter()
{
Format = BarcodeFormat.QR_CODE,
Options = new ZXing.Common.EncodingOptions
{
Height = 600,
Width = 600
}
};
Other examples I have seen call BarcodeWriter() like above just fine, https://csharp.hotexamples.com/examples/ZXing/BarcodeWriter/-/php-barcodewriter-class-examples.html to list a few.我见过的其他例子像上面那样调用 BarcodeWriter() 就好了, https://csharp.hotexamples.com/examples/ZXing/BarcodeWriter/-/php-barcodewriter-class-examples.html列出了一些。
Why does calling BarcodeWriter require a type argument.为什么调用 BarcodeWriter 需要类型参数。 How can I properly instansiate an instance of a BarcodeWriter?
如何正确实例化 BarcodeWriter 的实例?
If you use ZXing.Net with.Net Standard, you have to add one additional package with a specific implementation of the barcode reader and writer classes for the image manipulation library that you want to use.如果您将 ZXing.Net 与 .Net Standard 一起使用,则必须添加一个额外的 package,其中包含您要使用的图像处理库的条码读取器和写入器类的特定实现。
On Windows for example, you need to use this package: https://www.nuget.org/packages/ZXing.Net.Bindings.Windows.Compatibility/例如,在 Windows 上,您需要使用此 package: https://www.nuget.org/packages/ZXing.Net.Bindings.Windows.Compatibility/
more info here: https://github.com/micjahn/ZXing.Net/issues/370更多信息在这里: https://github.com/micjahn/ZXing.Net/issues/370
The problem is you are using BarcodeWriter from the wrong namespace. 问题是您使用了来自错误名称空间的BarcodeWriter。
You should be using ZXing.Mobile.BarcodeWriter
whereas you are using ZXing.BarcodeWriter
, try the below and see if that works for you: 您应该使用
ZXing.Mobile.BarcodeWriter
而您正在使用ZXing.BarcodeWriter
,请尝试以下方法,看看是否适合您:
var barcodeWriter = new ZXing.Mobile.BarcodeWriter
{
Format = ZXing.BarcodeFormat.QR_CODE,
Options = new ZXing.Common.EncodingOptions
{
Height = 600,
Width = 600
}
};
I fixed the issue. 我解决了这个问题。 BarcodeWriter can be instantiated as expected when used natively in the android project, in my original question I was attempting to use it within the cross platform Xamarin part of the project.
当在Android项目中本地使用BarcodeWriter时,可以按预期实例化它。在我最初的问题中,我试图在项目的跨平台Xamarin部分中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.