C # generate a QR code,
Reference ZXing class library
Functions:
1 generate a QR code with a Logo
2. Draw the QR code to the image.
3. Draw text on the Image
Generate QR code
1 public string CreateQrCode (string md5Str, string name, int sex) 2 {3 string str = sex = 1? "Sir": "Ms"; 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) // create the file folder 9 {10 Directory if it does not exist. 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}
Generate text on the Image