二维码 ThoughtWorks.QRCode 简单使用实例

目前在使用中接触比较多的是ThoughtWorks.QRCodeQrCode.Net两种方式,自己最近在用ThoughtWorks.QRCode,供大家参考。

直接上代码:

namespace SDFeng.Utils
{
    public class QRCodeUtil
    {
        private static QRCodeEncoder qrCodeEncoder = null;

        public static Image CreateImage(string enCodeString)
        {
            InitQRCodeEncoder();

            Bitmap bt = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8);
            return bt;
        }

        private static void InitQRCodeEncoder()
        {
            if (qrCodeEncoder == null)
            {
                qrCodeEncoder = new QRCodeEncoder();
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; //  support different mode
                qrCodeEncoder.QRCodeScale = 50;
                qrCodeEncoder.QRCodeVersion = 0;
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L; // support different mode
            }
            else
            {
                qrCodeEncoder.QRCodeVersion = 0;
            }
        }
    }
}

thoughtworks.qrcode.dll 下载地址:

http://download.csdn.net/detail/u012543266/9770135


你可能感兴趣的:(编程综合)