zoukankan      html  css  js  c++  java
  • 二维码生成基于Gma.QrCodeNet.Encoding

    参考:http://www.cnblogs.com/vmyspace/archive/2012/04/05/2433233.html

    今天,项目需要,参考资料写了个二维码生成后台  基于Gma.QrCodeNet.Encoding

    前台html直接请求地址,固定图片高宽就能用。

    using System;
    using System.Collections.Generic;
    using System.Web;
    using Gma.QrCodeNet.Encoding;
    using System.IO;
    using System.Text;
    using System.Drawing;
    using System.Drawing.Drawing2D;


    namespace TestWeb.erweima_test
    {
        /// <summary>
        /// Handler2 的摘要说明
        /// </summary>
        public class Handler2 : IHttpHandler
        {

            public void ProcessRequest(HttpContext context)
            {
                if (!string.IsNullOrEmpty(context.Request["qrdata"].ToString()))
                {
                    CreateQr(context);
                }
               
            }

            public void CreateQr(HttpContext context)
            {
                QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
                QrCode qrCode = new QrCode();
                //String data = "0150204whxtl/?type=invate";
                String data = context.Request["qrdata"].ToString() ;
                //String data = context.Request.QueryString["qrdata"].ToString();
                System.Drawing.Bitmap image;
                qrCode = qrEncoder.Encode(data);
                image = new Bitmap(qrCode.Matrix.Width * 5, qrCode.Matrix.Height * 5);
                image.SetResolution(180f, 180f);
                Graphics gdiobj = Graphics.FromImage(image);
                gdiobj.CompositingQuality = CompositingQuality.HighQuality;
                gdiobj.SmoothingMode = SmoothingMode.HighQuality;
                gdiobj.InterpolationMode = InterpolationMode.HighQualityBicubic;
                gdiobj.PixelOffsetMode = PixelOffsetMode.HighQuality;

                for (Int32 i = 0; i < qrCode.Matrix.Height; i++)
                {
                    for (Int32 j = 0; j < qrCode.Matrix.Width; j++)
                    {
                        if (qrCode.Matrix.InternalArray[i, j])
                        {
                            gdiobj.FillRectangle(new SolidBrush(Color.Black), i * 5, j * 5, 5, 5);
                        }
                    }
                }

                System.Drawing.Imaging.EncoderParameters ep = new System.Drawing.Imaging.EncoderParameters(1);
                ep.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 800L);

                System.IO.MemoryStream MStream = new System.IO.MemoryStream();
                image.Save(MStream, System.Drawing.Imaging.ImageFormat.Png);
                // image.Save(MStream, null, ep);
                context.Response.ClearContent();
                context.Response.ContentType = "image/Png";
                context.Response.BinaryWrite(MStream.ToArray());
            
            
            }

            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }

  • 相关阅读:
    IIS浏览显示目录
    图解NuGet的安装和使用
    未能找到类型或命名空间名称“DbContext”
    IIS报错:未将对象引用设置到对象的实例
    最新11位手机号正则表达式
    Sql Server连表查询字段为null
    sql server 表连接
    2019用卡提额攻略
    win10,7 80端口被占用的检测和解决方法
    SAP之RFC_READ_TABLE
  • 原文地址:https://www.cnblogs.com/wangxianchao/p/4283568.html
Copyright © 2011-2022 走看看