/// <summary> /// 生成二维码图片 /// </summary> /// <param name="invitedcode">邀请码</param> private void saveQRCode(string invitedcode) { string Opath = HttpContext.Current.Server.MapPath("~/FileImg");// @"D:\VedioCapture\Photo"; string path = Opath + "\\" + invitedcode + ".jpg"; if (!Directory.Exists(Opath)) { Directory.CreateDirectory(Opath); } if (!System.IO.File.Exists(path))//确定指定的文件是否存在 { Bitmap objPic, objNewPic, bit; try { objPic = new Bitmap(QRCode.CreateImage(string.Format(Settings.Instance.QRCodeLink, invitedcode))); Image ig = Image.FromFile(HttpContext.Current.Server.MapPath("~/FileImg/PicIco.png")); bit = (Bitmap)QRCode.CombinImage(objPic, ig); objNewPic = new Bitmap(bit, 120, 120);//图片保存的大小尺寸 objNewPic.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (Exception exp) { } finally { objPic = null; objNewPic = null; bit = null; } } }
/// <summary> /// 生成二维码图片 /// </summary> /// <param name="str">二维码信息</param> /// <param name="path">文件保存路径</param> /// <param name="fileName">文件名 包含后缀</param> private bool SaveQRCode(string str, string path, string fileName) { //创建文件夹 if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } //存在转发送 if (File.Exists(path + fileName)) { return(true); } Bitmap objPic, objNewPic, bit; try { objPic = new Bitmap(QRCode.CreateImage(str)); Image ig = Image.FromFile(HttpContext.Current.Server.MapPath("~/FileImg/PicIco.png")); bit = (Bitmap)QRCode.CombinImage(objPic, ig); //objNewPic = new Bitmap(bit, 150, 150); objNewPic = new Bitmap(bit, 3000, 3000); objNewPic.Save(path + fileName, System.Drawing.Imaging.ImageFormat.Jpeg); objNewPic.Dispose(); objNewPic = null; objPic.Dispose(); objPic = null; return(true); } catch (Exception ex) { LoggerHelper.Error(ex.ToString()); return(false); } finally { objPic = null; objNewPic = null; bit = null; } }