ZXing.NetでQRコード読み取り(C#)
仕事で必要になったのでメモ。
ZXingのバグ?か、BarcodeReader.Decodeメソッドに食わせる画像によっては、
例外発生するみたい。
(公式のサンプルプログラムでも同様の現象を確認)
private BarcodeReader barcodeReader = new BarcodeReader(); //クラスのメンバとする public Form1() { InitializeComponent(); barcodeReader.AutoRotate = true; barcodeReader.TryInverted = true; } private string readQR(Bitmap bmp) { string ret = "(not found)"; try { Result result = barcodeReader.Decode(bmp); if (result != null) { ret = result.Text; } } catch { //ZXingのバグ?barcodeReader.Decodeに失敗することがある ver 0.14.0.0 で確認 } return ret; } }