我正在使用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是包含解碼函數的類的對象。
以下是無法解碼的圖像。
我試着試着在以下網站對其進行解碼。在那裏解碼。
http://www.patrick-wied.at/static/qrgen/
而下面的圖像被成功解碼。
請幫我解決這個問題
::然後,我該怎麼辦?任何建議使我的程序準確? –
重新載入Java代碼? –
我想在c# –