一、引用

二、代码
帮助类
private static string QRCodeDirectory = "QRCode";
public static System.DrawingCore.Bitmap GenerateQRCode(string conetnt, string logoPath = "", int height = 240, int width = 240, int margin = 0)
BarcodeWriter barCodeWriter = new BarcodeWriter();
barCodeWriter.Format = BarcodeFormat.QR_CODE;
barCodeWriter.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");
barCodeWriter.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H);
barCodeWriter.Options.Height = height;
barCodeWriter.Options.Width = width;
barCodeWriter.Options.Margin = margin;
BitMatrix bm = barCodeWriter.Encode(conetnt);
System.DrawingCore.Bitmap qrCodeImage = barCodeWriter.Write(bm);
if (!string.IsNullOrEmpty(logoPath))
System.DrawingCore.Bitmap logo = new System.DrawingCore.Bitmap(logoPath);
int logoSize = (int)(qrCodeImage.Width * 0.2);
int logoX = (qrCodeImage.Width - logoSize) / 2;
int logoY = (qrCodeImage.Height - logoSize) / 2;
System.DrawingCore.Graphics qrGraphics = System.DrawingCore.Graphics.FromImage(qrCodeImage);
qrGraphics.DrawImage(logo, new System.DrawingCore.Rectangle(logoX, logoY, logoSize, logoSize));
public static byte[] Create(string message, int width = 600, int height = 600)
if (string.IsNullOrWhiteSpace(message))
var w = new QRCodeWriter();
BitMatrix b = w.encode(message, BarcodeFormat.QR_CODE, width, heig);
var zzb = new BarcodeWriter();
zzb.Options = new EncodingOptions()
byte[] bytes = BitmapToArray(b2);
public static byte[] BitmapToArray(System.DrawingCore.Bitmap bmp)
using (MemoryStream stream = new MemoryStream())
bmp.Save(stream, ImageFormat.Png);
byteArray = stream.GetBuffer();

调用
public byte[] GetQrCode(string qrUrl)
System.DrawingCore.Bitmap qrImage = null;
if (!System.IO.File.Exists(QRCodeLogoPath))
qrImage = ZXingHelper.GenerateQRCode(qrUrl);
qrImage = ZXingHelper.GenerateQRCode(qrUrl, QRCodeLogoPath);
MemoryStream ms = new MemoryStream();
qrImage.Save(ms, System.DrawingCore.Imaging.ImageFormat.Bmp);
byte[] bytes = ms.GetBuffer();