zoukankan      html  css  js  c++  java
  • C#生成二维码

    首先引用ThoughtWorks.QRCode.dll

    代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    using ThoughtWorks.QRCode.Codec;
    
    namespace QRCodeUtil
    {
        /// <summary>
        /// 二维码生成
        /// </summary>
        public class QRCodeHelper
        {
            #region 根据链接获取二维码
            /// <summary>
            /// 根据链接获取二维码
            /// </summary>
            /// <param name="link">链接</param>
            /// <returns>返回二维码图片</returns>
            public static Bitmap GetQRCodeBmp(string link)
            {
                QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                qrCodeEncoder.QRCodeScale = 4;
                qrCodeEncoder.QRCodeVersion = 0;
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                Bitmap bmp = qrCodeEncoder.Encode(link);
    
                return bmp;
            }
            #endregion
    
        }
    }
    View Code

    使用示例:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    using QRCodeUtil;
    
    namespace SWX
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Bitmap bmp = QRCodeHelper.GetQRCodeBmp(@"http://www.baidu.com/");
                string str = HttpContext.Current.Request.MapPath("\aa.bmp");
                bmp.Save(str);
            }
        }
    }
    View Code
  • 相关阅读:
    堆栈(线性表)
    链表 -- 循环链表(线性表)
    链表 -- 单向链表(线性表)
    排序算法--归并算法(强分治)
    sqlhelper
    sqlite与sqlserver区别
    常用sql集锦
    外出实施问题总结
    JS深入理解系列(一):编写高质量代码
    通用分页(Jquery版)
  • 原文地址:https://www.cnblogs.com/s0611163/p/4056412.html
Copyright © 2011-2022 走看看