首页 > 解决方案 > C# Winforms ID 条码阅读器使用 ZXing.Net

问题描述

我正在尝试使用带有 ZXing.net 库的 C# Winforms 应用程序来制作 ID 阅读器。

我找到了一个像这样的简单示例,但效果不佳,两个结果始终为空

我试图弄清楚问题是什么!

IBarcodeReader reader = new BarcodeReader();
reader.Options.PossibleFormats = new List<BarcodeFormat>();
reader.Options.PossibleFormats.Add(BarcodeFormat.PDF_417);
reader.Options.PossibleFormats.Add(BarcodeFormat.RSS_14);
reader.Options.TryHarder = true;

var barcodeBitmap = (Bitmap)Image.FromFile("d:\\5.png");
var res1 = reader.Decode(barcodeBitmap);
var res2 = reader.DecodeMultiple(barcodeBitmap);

任何帮助!

标签: c#winformsreaderzxing.net

解决方案


当结果为 null 时,表示图像无法解码为任何PossibleFormats. 如果您不确定条码/二维码的格式,您可以简单地删除所有预期的格式,以使其接受任何格式:

IBarcodeReader reader = new BarcodeReader();

using (var barcodeBitmap = (Bitmap)Image.FromFile(@"d:\5.png"))
{
    var result = reader.Decode(barcodeBitmap);
    if (result != null)
    {
        Console.WriteLine(result.Text);
        // You can also use the following to determine the Barcode format.
        Console.WriteLine(result.BarcodeFormat.ToString());
    }
}

推荐阅读