2012-11-02 99 views
0

我正在使用zXing C#库来解码VS 2010中winforms应用程序中的QR码。它对一些图像正常工作,但对于少数图像无效。zXing:无法读取有效的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是包含解码函数的类的对象。

以下是无法解码的图像。

Qr code that fails to decode
我试着试着在以下网站对其进行解码。在那里解码。
http://www.patrick-wied.at/static/qrgen/

而下面的图像被成功解码。

Qr code that decoded successfully

请帮我解决这个问题

回答

0

C#的端口是有点老,而不是维护。它看起来像是你的二进制化问题,或者是端口的一些问题,因为主分支(Java)解码了这些罚款:

http://zxing.org/w/decode?u=http%3A%2F%2Fi.stack.imgur.com%2FTEiIH.jpg&full=true http://zxing.org/w/decode?u=http% 3A%2F%2Fi.stack.imgur.com%2FP8irV.png & full = true

+0

::然后,我该怎么办?任何建议使我的程序准确? –

+0

重新载入Java代码? –

+0

我想在c# –