生成二维码

       Bitmap bt;
            if (!string.IsNullOrEmpty(this.hiErWeiMa.Value))
            {
                string enCodeString = this.hiErWeiMa.Value;
                //生成设置编码实例
                QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                //设置二维码的规模,默认4
                qrCodeEncoder.QRCodeScale = 4;
                //设置二维码的版本,默认7
                qrCodeEncoder.QRCodeVersion = 7;
                //设置错误校验级别,默认中等
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                //生成二维码图片
                bt = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8);
                if (!System.IO.Directory.Exists(Server.MapPath("~/Upload_Files/UserCode/")))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath("~/Upload_Files/UserCode/"));//不存在就创建目录
                }
                if (!File.Exists(Server.MapPath("~/Upload_Files/UserCode/") + enCodeString + ".jpg"))
                {
                    bt.Save(Server.MapPath("~/Upload_Files/UserCode/") + enCodeString + ".jpg");
                }
                //图片控件要显示的二维码图片路径
                string src = "../../Upload_Files/UserCode/" + enCodeString + ".jpg";
                ScriptManager.RegisterStartupScript(this.Page, GetType(), "", "d('" + src + "')", true);
            }

posted on 2017-11-28 16:07  New_q  阅读(241)  评论(0编辑  收藏  举报

导航