c# - 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);
任何帮助!
解决方案
当结果为 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());
}
}
推荐阅读
- java - 字段已正确验证,但视图中未显示错误
- java - 查询返回空游标
- angular - 来自 Terser 无效分配的 scrips.xxx.js 中的错误
- c - Posix Pthreads 的同步在读写器问题中不起作用
- xamarin.android - Crashlytics 日志显示 java 文件行号而不是 cs 文件
- angular - 从某个函数中获取数据并将其用作 formModel 参数的默认值
- html - 如何调整图像数组和文本的大小以最适合父容器?
- algorithm - 基于两个变量调用两次递归函数的 Big-O
- java - Java 性能大
- r - 在问答论坛中抓取日期