代码来源:https://github.com/codebude/QRCoder 的demo
private void RenderQrCode() { string level = comboBoxECC.SelectedItem.ToString(); QRCodeGenerator.ECCLevel eccLevel = (QRCodeGenerator.ECCLevel)(level == "L" ? 0 : level == "M" ? 1 : level == "Q" ? 2 : 3); using (QRCodeGenerator qrGenerator = new QRCodeGenerator()) { using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(textBoxQRCode.Text, eccLevel)) { using (QRCode qrCode = new QRCode(qrCodeData)) { pictureBoxQRCode.BackgroundImage = qrCode.GetGraphic(20, Color.Black, Color.White, GetIconBitmap(), (int) iconSize.Value); this.pictureBoxQRCode.Size = new System.Drawing.Size(pictureBoxQRCode.Width, pictureBoxQRCode.Height); //Set the SizeMode to center the image. this.pictureBoxQRCode.SizeMode = PictureBoxSizeMode.CenterImage; pictureBoxQRCode.SizeMode = PictureBoxSizeMode.StretchImage; } } } } private Bitmap GetIconBitmap() { Bitmap img = null; if (iconPath.Text.Length > 0) { try { img = new Bitmap(iconPath.Text); } catch (Exception) { } } return img; }
附件附上图片及编译好的汉化过得qrcoder.dll
qrcoder.dll 目前支持.netframework 3.5以上