【问题标题】:ZXing - Using the generic type BarcodeWriter<TOutput> requires 1 type argument ZXing.NET.MobileZXing - 使用泛型 BarcodeWriter<TOutput> 需要 1 个类型参数 ZXing.NET.Mobile
【发布时间】:2019-02-28 02:04:57
【问题描述】:

我一直在尝试使用 ZXing.Net.Mobile 和 ZXing.Net.Mobile.Forms 生成 QRCode: https://github.com/Redth/ZXing.Net.Mobile 并遇到以下错误:

"严重性代码描述项目文件行抑制状态 错误 CS0305 使用通用类型“BarcodeWriter”需要 1 个类型参数 TestApp.Android G:\Tests\TestApp\TestApp\TestApp.Android\SelectedBookingPage.cs 70 活动 "

这是我的代码:

BarcodeWriter writer = new BarcodeWriter()
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Height = 600,
                    Width = 600
                }
            };

我见过的其他例子像上面一样调用 BarcodeWriter() 就可以了,https://csharp.hotexamples.com/examples/ZXing/BarcodeWriter/-/php-barcodewriter-class-examples.html 列出了一些。

为什么调用 BarcodeWriter 需要类型参数。如何正确实例化 BarcodeWriter 的实例?

【问题讨论】:

    标签: c# xamarin xamarin.android zxing


    【解决方案1】:

    我解决了这个问题。 BarcodeWriter 在 android 项目中本地使用时可以按预期实例化,在我最初的问题中,我试图在项目的跨平台 Xamarin 部分中使用它。

    【讨论】:

      【解决方案2】:

      问题是您从错误的命名空间中使用 BarcodeWriter。

      您应该使用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
                  }
              };
      

      【讨论】:

      • 当我尝试得到以下错误:类型或命名空间名称“BarcodeWriter”不存在于命名空间“ZXing.Mobile”中。似乎命名空间仅包含与 MobileBarcodeScanner 相关的项目。
      • 你应该尝试使用ZXing的2.3.2版本
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 2023-03-03
      相关资源
      最近更新 更多