使用一般处理程序,扫描一维二维码

	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
    }

新手上路,有什么问题欢迎指出!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值