引用ZXing類庫 實現功能: 1生成帶有Logo二維碼 2 將二維碼繪製到圖片上 3 圖片上繪製文字 1 public string CreateQrCode(string md5Str,string name,int sex) 2 { 3 string str = sex == 1? "先生": ...
引用ZXing類庫
實現功能:
1生成帶有Logo二維碼
2 將二維碼繪製到圖片上
3 圖片上繪製文字
生成二維碼
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 }圖片上生成文字