【发布时间】:2023-08-26 15:55:02
【问题描述】:
我正在尝试使用这个库 https://zxingnet.codeplex.com/ 。 图片已在本站https://zxing.org/w/decode.jspx 上成功解码,但在我的代码中没有。
以下是我尝试过的两种方法:
BarcodeReader reader = new BarcodeReader { AutoRotate = true, TryHarder = true, TryInverted = true, PossibleFormats = fmts };
Result result = reader.Decode(new Bitmap(@"D:\\6.jpg"));
和:
public static byte[] ImageToByte(Bitmap img)
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}
MultiFormatReader m_BarcodeReader = new MultiFormatReader();
var hints = new Dictionary<DecodeHintType, object>();
var fmts = new List<BarcodeFormat>();
fmts.Add(BarcodeFormat.EAN_13);
hints.Add(DecodeHintType.TRY_HARDER_WITHOUT_ROTATION, false);
hints.Add(DecodeHintType.POSSIBLE_FORMATS, fmts);
Result rawResult;
Bitmap image = new Bitmap(@"D:\\6.jpg");
RGBLuminanceSource r = new RGBLuminanceSource(ImageToByte(image), image.Width, image.Height);
GlobalHistogramBinarizer x = new
HybridBinarizer(r);
BinaryBitmap bitmap = new BinaryBitmap(x);
try
{
rawResult = m_BarcodeReader.decode(bitmap, hints);
if (rawResult != null)
{
return rawResult.Text;
}
}
catch (ReaderException e)
{
}
在这两种情况下,解码结果都是null。我在这里做错了什么?
这是示例图片:
【问题讨论】:
-
您尝试过简单的条形码图像吗?
-
你能在windows窗体中显示图像吗?也许调整高度、宽度、左上角,这样只有条形码被传递给扫描仪。必要时旋转图像。
-
@VishnuPrasad,它在我无法检测到的非常特殊的情况下在这里和那里工作。大多数情况下它只是不起作用,而每张图片都在网站上解码zxing.org/w/decode.jspx
-
@jdweng,它应该自动取条码,无需干预。
-
如果有人会搜索这个,我放弃了这个工作并与另一个 freebarcode.codeplex.com 一起工作。最后一个工作完美。
标签: c# barcode zxing barcode-scanner