【问题标题】:When I try to save a QR code from the Zxing library I get an error with the BarcodeWriter class当我尝试从 Zxing 库中保存 QR 码时,BarcodeWriter 类出现错误
【发布时间】:2022-04-29 13:25:24
【问题描述】:

目前我想将我生成的二维码作为图像存储在执行它的电话库中,然后几乎同时将其作为备份上传到亚马逊 AWS,但是当我尝试将我的二维码写为图像时出现错误.

代码:

private void WriteBarcode()
{
    ZXing.BarcodeWriter barcodeWriter = new ZXing.BarcodeWriter
    {
        Format = BarcodeFormat.QR_CODE
    };
    barcodeWriter
        .Write("some string data")
        .Save(@"C:\some path");
}

我看到的这段代码应该可以工作,但它标记了 BarcodeWriter 类中的错误,并且我安装了以下依赖项。

Zxing.net
Zxing.Net.Mobile 
Zxing.Net.Mobile.Forms 

错误

Gravedad Código 描述 Proyecto Archivo Línea Estado suprimido 错误 CS0305 El uso de tipo de tipo genérico 'BarcodeWriter'

用途:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Xamanimation;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using ZXing.Net.Mobile.Forms;
using ZXing.Mobile;

当我输入 ZXing.Mobile.BarcodeWriter 时,它给了我一个错误并说它找不到那个命名空间

【问题讨论】:

标签: c# xamarin xamarin.forms qr-code zxing


【解决方案1】:

如果我用 Image 类型声明 BarcodeWriter,它对我有用:

var barcodeWriter = new ZXing.BarcodeWriter<Image>();

【讨论】:

    【解决方案2】:

    您必须将 ZXing 绑定包之一添加到您的项目中。 https://www.nuget.org/packages?q=ZXing.Bindings ZXing.Net 包中针对 .Net Standard 或 .Net Core 等目标的程序集仅包含基本实现,没有特定的图像类。这是因为 .Net 标准没有声明 System.Drawing 命名空间。默认情况下,这种 .Net 目标没有可用的 Bitmap 类或类似类。 绑定包为不同的图像库提供了特定的 BarcodeWriter 和 BarcodeReader 实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-26
      • 1970-01-01
      • 1970-01-01
      • 2021-04-20
      • 1970-01-01
      • 2015-11-04
      • 2023-04-08
      相关资源
      最近更新 更多