【转】C# 二维码生成

    /// <summary>
    /// 含有QR码的描述类和包装编码和渲染
    /// </summary>
    public class QRCodeHelper
    {
        /// <summary>
        /// 获取二维码
        /// </summary>
        /// <param name="strContent">待编码的字符</param>
        /// <param name="ms">输出流</param>
        ///<returns>True if the encoding succeeded, false if the content is empty or too large to fit in a QR code</returns>
        public static bool GetQRCode(string strContent, MemoryStream ms)
        {
            ErrorCorrectionLevel Ecl = ErrorCorrectionLevel.M; //误差校正水平 
            string Content = strContent;//待编码内容
            QuietZoneModules QuietZones = QuietZoneModules.Two;  //空白区域 
            int ModuleSize = 12;//大小
            var encoder = new QrEncoder(Ecl);
            QrCode qr;
            if (encoder.TryEncode(Content, out qr))//对内容进行编码,并保存生成的矩阵
            {
                var render = new GraphicsRenderer(new FixedModuleSize(ModuleSize, QuietZones));
                render.WriteToStream(qr.Matrix, ImageFormat.Png, ms);
            }
            else
            {
                return false;
            } 
            return true;
        } 

    }

通过上述方法即可实现二维码的生成,得到数据流MemoryStream 然后转换成Bitmap即可显示。
上述方法调用了QrCode.Net类库的Net35版本

QrCode.Net 下载地址:http://qrcodenet.codeplex.com/

原文地址: http://blog.csdn.net/paolei/article/details/12584295

参考地址:http://www.cnblogs.com/Soar1991/archive/2012/03/30/2426115.html

原文地址:https://www.cnblogs.com/mqxs/p/3482160.html