C#二维码生成


    public string GetQrCodeImageUrl(string res)
    {
       
        JObject obj = (JObject)JsonConvert.DeserializeObject(res);
        string JGDM = obj["data"]["JGDM"].ToString();
        string GetUrl = "http://baidu/";//定义
        string msg = "";
        Enterprises model = EnterprisesService.GetEnterprisesByJGDm(JGDM);
        if (model != null)
        {
            try
            {
                string path = Server.MapPath("/Ent/XCXQrCode/" + model.OrganizationCode + ".jpg");
                if (!File.Exists(path))
                {
                   // string key = "";
                    string tempPath = Server.MapPath("/Ent/XCXQrCode/");
                    if (!Directory.Exists(tempPath))
                        Directory.CreateDirectory(tempPath);
                    //else DeleteFolder(tempPath);
                    string url = GetUrl+"Ent/QrCodeMsg.aspx?JGDM=" + model.OrganizationCode + "&EnterpriseName=" + model.EnterpriseName+ "";
                    string logopath = Server.MapPath("/Images/QrCodelogo.png");//中间log
                    string ImagePath = QRCodeHelper.CreateQRCode_ByLogo("/Ent/XCXQrCode/", url, logopath);//保存文件路径、二维码内容、logo路径
                    msg = ImagePath;

                    string SavePath_f = tempPath + ImagePath.Replace("/Ent/XCXQrCode/", "");
                    System.Drawing.Image img = System.Drawing.Image.FromFile(SavePath_f);
                    Bitmap bmp = new Bitmap(img.Width + 60, img.Height + 80);

                    Graphics g = Graphics.FromImage(bmp);
                    Brush bush_bj = new SolidBrush(Color.White);
                    g.FillRectangle(bush_bj, new Rectangle(0, 0, img.Width + 60, img.Height + 120));
                    Rectangle rec = new Rectangle();
                    rec.Height = img.Height;
                    rec.Width = img.Width;
                    rec.X = 30;
                    rec.Y = 35;
                    g.DrawImage(img, rec);

                    Font myFont = new Font("宋体", 12, FontStyle.Bold);
                    Brush bush = new SolidBrush(Color.Black);
                    Rectangle frec = new Rectangle();
                    frec.Height = 25;
                    frec.Width = img.Width;
                    frec.X = 50;
                    frec.Y = 10;
                    g.DrawString(" ", myFont, bush, frec);

                    Font myFont1 = new Font("宋体", 10, FontStyle.Regular);
                    Rectangle frecd = new Rectangle();
                    frecd.Height = 50;
                    frecd.Width = img.Width;
                    frecd.X = 20;
                    frecd.Y = img.Height + 40;
                    StringFormat sf = new StringFormat();
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Center;
                    g.DrawString(model.EnterpriseName, myFont1, bush, frecd, sf);

                    string SavePath_s = model.OrganizationCode + ".jpg";//图片保存到文件夹下
                    bmp.Save(tempPath + SavePath_s);
                    msg = GetUrl + "/Ent/XCXQrCode/" + SavePath_s;
                }
                else
                {
                    msg = GetUrl + "/Ent/XCXQrCode/" + model.OrganizationCode + ".jpg";
                }
            }
            catch (Exception ex)
            {
                msg = "该二维码未生成!";
            }
        }
        else { msg = "该二维码未生成!"; }
        return JsonConvert.SerializeObject(msg);
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值