【发布时间】:2011-12-01 10:13:05
【问题描述】:
我在 C# 中使用此代码来解码(不检测)二维码,它可以工作:
LuminanceSource ls = new RGBLuminanceSource(image, image.Width, image.Height);
Result result = new QRCodeReader().decode(new BinaryBitmap(new HybridBinarizer(ls)));
现在我想在更复杂的图像中检测二维码,其中包含许多其他内容,例如图像和文本。我无法理解如何做到这一点,因为我找不到任何样本并且将 Bitmap (C#) 转换为 Bitmatrix for Detector (zxing) 并不那么直接。
有人给我一段代码吗?
非常感谢
更新
我尝试了这段代码,但得到了 ReaderException:
代码:
LuminanceSource ls = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);
QRCodeMultiReader multiReader = new QRCodeMultiReader();
Result[] rs = multiReader.decodeMultiple(new BinaryBitmap(new HybridBinarizer(ls)), hints);
return rs[0].Text;
异常
com.google.zxing.ReaderException:
in com.google.zxing.qrcode.detector.FinderPatternFinder.selectBestPatterns()
in com.google.zxing.qrcode.detector.FinderPatternFinder.find(Hashtable hints)
in com.google.zxing.qrcode.detector.Detector.detect(Hashtable hints)
in com.google.zxing.qrcode.QRCodeReader.decode(BinaryBitmap image, Hashtable hints)
in com.google.zxing.qrcode.QRCodeReader.decode(BinaryBitmap image)
in ...Logic.BarCodeManager.QRCodeReader(Bitmap bitmap) in
2011 年 2 月 12 日更新
我刚刚尝试使用 iPhone 上的应用程序扫描打印的二维码(帖子顶部的代码),效果很好!所以问题肯定在检测/解码阶段。
【问题讨论】:
-
我认为这是 QRCode 的问题...因为只有 10 张图片的 1 张代码已被解码!在其他情况下,会引发 com.google.zxing.ReaderException!