using System;
using System.Collections.Generic;
using System.Drawing;
using System.Web;
using ThoughtWorks.QRCode.Codec;
using ThoughtWorks.QRCode.Codec.Data;
using ZXing;
using ZXing.Common;
/// <summary>
/// 解析一维二维码
/// </summary>
/// <param name="context"></param>
public void sys(HttpContext context)
{
bool lb_result = false;
var filePath = @"C:\Users\Administrator\Desktop\BB9FD8B7BE87DFA63E380FFB4624FCA5.jpg";
if (!System.IO.File.Exists(filePath))
return;
Bitmap myBitmap = new Bitmap(Image.FromFile(filePath));
#region 方法1
//QRCodeDecoder decoder = new QRCodeDecoder();
//string decodedString = decoder.decode(new QRCodeBitmapImage(myBitmap));
//context.Response.Write(decodedString);
#endregion
#region 方法2
//1设置读取条形码规格
DecodingOptions dr = new DecodingOptions();
dr.PossibleFormats = new List<BarcodeFormat>()
{
BarcodeFormat.QR_CODE
};
//2进行读取操作
BarcodeReader br = new BarcodeReader();
br.Options = dr;//指定规格
Result rs = br.Decode(myBitmap);
if (rs == null)
{
//context.Response.Write("读取失败");
dr.PossibleFormats = new List<BarcodeFormat>() {
BarcodeFormat.EAN_13
};
Result result = br.Decode(myBitmap);//进行读取条形码数字
if (result == null)
{
context.Response.Write("扫描失败!");
}
else
{
context.Response.Write(result.Text);
}
}
else
{
context.Response.Write(rs.Text);
}
#endregion
}
新手上路,有什么问题欢迎指出!