C#QRコード生成

4151 ワード

    /// <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;

        } 



    }

上記の方法でQRコードの生成を実現し、データストリームMemoryStreamを得てBitmapに変換すれば表示できる.上記の方法ではQrCodeが呼び出す.NetクラスライブラリのNet 35バージョン
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