C# ZXing C# Zbar

今天找了点时间看了一下二维码的识别和生成

1、ZXing可以直接识别和生成多种多种二维码

生成是有长宽可选用参数、我做时候,给限定了最小值,免得变形严重。

options = new QrCodeEncodingOptions

{

DisableECI = true,

CharacterSet = "UTF-8",

Width = type == 3 ? width : 30,

Height = type == 3 ? height : 30,

Margin = 0,

PureBarcode = true

};

2、zbar,对CODE39、CODE128支持还不错,对PDF_417支持,我看到有该属性,怎么跳都不出来。有时间再继续研究下。

////// 条码识别

/// Zbar

///private string ScanBarCode(string fileName)

{

DateTime now = DateTime.Now;

Image primaryImage = Image.FromFile(fileName);

Bitmap pImg = MakeGrayscale3((Bitmap)primaryImage);

try

{

ZBar.ImageScanner scanner = new ZBar.ImageScanner();

//scanner.SetConfiguration(ZBar.SymbolType.None, ZBar.Config.Enable, 0);

//scanner.SetConfiguration(ZBar.SymbolType.CODE39, ZBar.Config.Enable, 1);

//scanner.SetConfiguration(ZBar.SymbolType.CODE128, ZBar.Config.Enable, 1);

//scanner.SetConfiguration(ZBar.SymbolType.PDF417, ZBar.Config.Enable, 1);

Listsymbols = new List();

symbols = scanner.Scan((Image)pImg);

if (symbols != null && symbols.Count > 0)

{

string result = string.Empty;

symbols.ForEach(s => result += "条码内容:" + s.Data + " 条码质量:" + s.Quality + Environment.NewLine);

return result;

}

return "-1|该图片中未识别到任何条码。";

}

catch (Exception e)

{

return "-1|该图片中未识别到任何条码。" + e.Message;

}

}

你可能感兴趣的:(C# ZXing C# Zbar)