【发布时间】:2012-11-02 17:55:14
【问题描述】:
我在 VS 2010 的 winforms 应用程序中使用 zXing C# 库解码 QR 码。它适用于某些图像,但对于少数图像则失败。
异常信息:
“抛出了 'com.google.zxing.ReaderException' 类型的异常。”
这是我的代码:
返回解码数据的函数代码
public string GetQRValue(Bitmap value)
{
string result = string.Empty;
try
{
QRCodeReader reader = new QRCodeReader();
//com.google.zxing.Reader re
com.google.zxing.LuminanceSource source = new RGBLuminanceSource(value, value.Width, value.Height);
var binarizer = new HybridBinarizer(source);
var binBitmap = new BinaryBitmap(binarizer);
result = reader.decode(binBitmap).Text;
}
catch(Exception ex)
{
result = ex.Message; //string.Empty;
}
return result;
}
调用上述函数的代码:
Bitmap image1 = (Bitmap)Image.FromFile(txtFile.Text , true);
lblData.Text = cls.GetQRValue(image1);
这里txtFile是文件的路径,cls是包含解码函数的类的对象。
下面是解码失败的图片。
我尝试在以下网站上对其进行解码。并在那里解码。
http://www.patrick-wied.at/static/qrgen/
并且下面的图片解码成功。
请帮我解决问题
【问题讨论】:
标签: winforms c#-4.0 decode qr-code zxing