QRCodeHelper.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. //using Spire.Barcode;
  8. using ThoughtWorks.QRCode.Codec;
  9. namespace EMIS.Utility
  10. {
  11. public class QRCodeHelper
  12. {
  13. public static Image GenerateQRCode(string code)
  14. {
  15. QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
  16. qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
  17. qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
  18. qrCodeEncoder.QRCodeVersion = 0;
  19. qrCodeEncoder.QRCodeScale = 4;
  20. //将字符串生成二维码图片
  21. Bitmap image = qrCodeEncoder.Encode(code, Encoding.Default);
  22. return image;
  23. ////保存为PNG到内存流
  24. //MemoryStream ms = new MemoryStream();
  25. //image.Save(ms, ImageFormat.Png);
  26. //BarcodeSettings barsetting = new BarcodeSettings();
  27. ////set the x dimension
  28. //barsetting.X = 0.8f;
  29. //barsetting.Unit = GraphicsUnit.Millimeter;
  30. //barsetting.HasBorder = true;
  31. //barsetting.BorderWidth = 0.5F;
  32. ////set the data
  33. //barsetting.Data = code;
  34. //barsetting.Data2D = code;
  35. //barsetting.QRCodeECL = QRCodeECL.H;
  36. //barsetting.ShowText = false;
  37. //barsetting.ShowTopText = false;
  38. //barsetting.ShowCheckSumChar = false;
  39. //barsetting.ShowTextOnBottom = false;
  40. ////generate UPCA barcode
  41. //barsetting.Type = BarCodeType.QRCode;
  42. //BarCodeGenerator bargenerator = new BarCodeGenerator(barsetting);
  43. //Image barcodeimage = bargenerator.GenerateImage();
  44. //return barcodeimage;
  45. }
  46. }
  47. }