http://www.cnblogs.com/jys509/p/4592539.html
C# 中使用 ThoughtWorks.QRCode.dll 生成指定尺寸和边框宽度的二维码
插件:
添加引用:
using System.Drawing; using ThoughtWorks.QRCode.Codec; using ThoughtWorks.QRCode.Codec.Data; using ThoughtWorks.QRCode.Codec.Util;
生成二维
public Bitmap NewCode(string str) { //初始化二维码生成工具 QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; qrCodeEncoder.QRCodeVersion = 0; qrCodeEncoder.QRCodeScale = 4; //将字符串生成二维码图片 Bitmap image = qrCodeEncoder.Encode(str, Encoding.Default); return image; }
public ActionResult Cre() { Bitmap image = createcode.NewCode(content); MemoryStream ms = new MemoryStream(); image.Save(ms, ImageFormat.Png); Response.BinaryWrite(ms.GetBuffer()); return null; }
<img src="@Url.Action("Cre")" />