c#二维码建立与识别

QrCodeEncodingOptions options = new QrCodeEncodingOptions();
options.CharacterSet = "UTF-8" ;
options.DisableECI = true ; // Extended Channel Interpretation (ECI) 主要用于特殊的字符集。并不是所有的扫描器都支持这种编码。
options.ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H; // 纠错级别
options.Width = 300;
options.Height = 300;
options.Margin = 1;
// options.Hints,更多属性,也可以在这里添加。
 
BarcodeWriter writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
writer.Options = options;
 
Response.Clear();
using (Bitmap bmp = writer.Write( "http://www.cftea.com" )) // Write 具备生成、写入两个功能
{
  MemoryStream ms = new MemoryStream();
  {
   bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
 
   Response.ContentType = "image/png" ;
   Response.BinaryWrite(ms.ToArray());
  }
}
Response.End();
 
 
 
QrCodeEncodingOptions options = new QrCodeEncodingOptions();
options.CharacterSet = "UTF-8" ;
options.Width = 300;
options.Height = 50;
options.Margin = 1;
options.PureBarcode = false ; // 是否是纯码,如果为 false,则会在图片下方显示数字
 
BarcodeWriter writer = new BarcodeWriter();
writer.Format = BarcodeFormat.CODE_128;
writer.Options = options;
 
Response.Clear();
using (Bitmap bmp = writer.Write( "12345678" ))
{
  MemoryStream ms = new MemoryStream();
  {
   bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
 
   Response.ContentType = "image/png" ;
   Response.BinaryWrite(ms.ToArray());
  }
}
Response.End();
 
 
BarcodeReader reader = new BarcodeReader();
reader.Options.CharacterSet = "UTF-8" ;
using (Bitmap bmp = new Bitmap( "D:\\qr.png" ))
{
  Result result = reader.Decode(bmp);
  Response.Write(result.Text);
}

你可能感兴趣的:(c#二维码建立与识别)