一,添加ThoughtWorks.QRCode.dll 引用
二,直接使用下面即可
namespace Sx.Office { public class QRCode { /// <summary> /// 生成二维码 /// </summary> /// <param name="message">二维码所要写入的信息</param> /// <param name="path">二维码图片的存储路径</param> public void Create(string message,string path) { Bitmap bt; string enCodeString = message; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); bt = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8); bt.Save(path); } /// <summary> /// 获取二维码的信息 /// </summary> /// <param name="path">二维码图片的存储路径</param> /// <returns>二维码信息</returns> public string DecodeMessage(string path) { QRCodeDecoder decoder = new QRCodeDecoder(); Bitmap bm = new Bitmap(path); return decoder.decode(new QRCodeBitmapImage(bm), Encoding.UTF8); } } }