ZXing.Net 从 0.16.5 升级到 0.16.6 后读取条码的标准方法

Standard way to read barcode after upgrading ZXing.Net from 0.16.5 to 0.16.6

将 ZXing.Net nuget 包从 0.16.5 升级到 0.16.6 后,现有源显示错误:

Using the generic type 'BarcodeReader' requires 1 type arguments

public void ReadBarcode(System.Drawing.Bitmap readerBitmap, BarcodeFormat barcodeFormat)
{
    // here when instantiate the barcode reader object 
    // the error occurs with the new updated nuget package 0.16.6
    var barcodeReader = new ZXing.BarcodeReader();

    barcodeReader.Options.PossibleFormats = new List<BarcodeFormat>();
    barcodeReader.Options.PossibleFormats.Add(barcodeFormat);
    barcodeReader.AutoRotate = true;
    barcodeReader.Options.TryHarder = true;
    barcodeReader.Options.PureBarcode = false;

    ZXing.Result barcodeResult = null;

    try
    {
        barcodeResult = barcodeReader.Decode(readerBitmap);
    }
    catch (Exception ex)
    {
        Log.LogError($"Exception in barcode lib - {ex.Message}");
    }

我应该从 BarcodeReader 更改为 BarcodeReaderGenericIBarcodeReaderIBarcodeReaderGeneric 还是应该添加参数 createLuminanceSource

我无法找到使用 0.16.6 的现有示例,甚至文档仍然显示无参数构造函数。

如果你走投无路,无法正确引用继承自BarcodeReader<Bitmap>BarcodeReader,你可以直接调用BarcodeReader<Bitmap>的基础构造函数,当您创建一个新的 BarcodeReader:

var luminanceSource = (Func<Bitmap, LuminanceSource>) (bitmap => new BitmapLuminanceSource(bitmap));
var barcodeReader = new ZXing.BarcodeReader<Bitmap>(null, luminanceSource, null);



//...so on
barcodeReader.Options.PossibleFormats = new List<BarcodeFormat>();
barcodeReader.Options.PossibleFormats.Add(barcodeFormat);

如果您将 ZXing.Net 与 .Net Core / .Net Standard 一起使用,则必须使用不同的绑定包之一。它们包含针对不同图像库的特定 BarcodeReader 实现。 https://www.nuget.org/packages?q=zxing.bindings 这是设计使然,因为 .Net 核心不在核心包中包含位图实现。