C#通过QRCode库生成二维码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

C#通过QRCode生成二维码

public  class QRCode
    {
        /// <summary>
        /// 根据ID生成一个二维码
        /// /// </summary>
        /// <param name="cardID"></param>
        /// <returns>二维码</returns>
        public  Image QREncoder(string cardID)
        {
            Image image = null;
            QRCodeEncoder encoder = new QRCodeEncoder();
            try
            {
                //设置编码类型
                encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                //设置尺寸
                encoder.QRCodeScale = 3;
                //设置版本
                encoder.QRCodeVersion = 2;
                //设置纠错
                encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
                image = encoder.Encode(cardID);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                image = null;
            }
            return image;
        }
        /// <summary>
        /// 根据二维码获取数据
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        //public string QRDecoder(Image image)
        //{
        //    string str = new QRCodeDecoder().decode(QRCodeBitmapImage(new Bitmap(image)));
        //    return str;
        //}
    }