引用ZXing类库
实现功能:
1生成带有Logo二维码
2 将二维码绘制到图片上
3 图片上绘制文字
class="code_img_closed" src="/Upload/Images/2017091910/0015B68B3C38AA5B.gif" alt="">logs_code_collapse">生成二维码
1 public string CreateQrCode(string md5Str,string name,int sex) 2 { 3 string str = sex == 1? "先生":"女士"; 4 string logoPath = AppDomain.CurrentDomain.BaseDirectory + "/logo.png"; 5 string qrCodePath = path + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg"; 6 string yqPath = AppDomain.CurrentDomain.BaseDirectory + "/yq2.jpg"; 7 string yqCardPath = path + TCommon.Md5(DateTime.Now.ToString("yyyyMMddHHmmss")) + ".jpg"; 8 if (Directory.Exists(path) == false)//如果不存在就创建file文件夹 9 { 10 Directory.CreateDirectory(path); 11 } 12 Generate3(md5Str,logoPath,qrCodePath); 13 Image qrCodeImg = new Bitmap(qrCodePath); 14 Image image = new Bitmap(yqPath); 15 Graphics ig = Graphics.FromImage(image); 16 Font font = new Font("Arial", 38,FontStyle.Bold); 17 Font font2 = new Font("STXINWEI", 38, FontStyle.Bold); 18 Brush brush = System.Drawing.Brushes.Black; 19 SizeF size = ig.MeasureString(name, font2); 20 SizeF size2 = ig.MeasureString(str, font); 21 ig.DrawString(name, font, brush, (720-size.Width-size2.Width) /2, 680); 22 ig.DrawString(str, font, brush, (720 - size.Width - size2.Width) / 2 + size.Width, 680); 23 ig.FillRectangle(Brushes.White, 280, 351, 160, 160); 24 ig.DrawImage(qrCodeImg, 285, 356); 25 image.Save(yqCardPath); 26 return yqCardPath.Substring(2); 27 }图片上生成文字