/// <summary>
/// 產生二維碼圖片
/// </summary>
/// <param name="formId">申請單號,作爲圖片名稱</param>
/// <param name="text">文本</param>
/// <param name="filePath">保存路徑</param>
public static void createQRCode(string formId,string text,string filePath)
{
try
{
EncodingOptions options = null;
BarcodeWriter writer = null;
//width、height为二维码图片的宽度和高度
int width = 120;
int height = 120;
var size = GetMinSize(text + formId); //获取内容尺寸,未经放大的最小尺寸
width = size[2] * (width / size[2]); //最大限度的宽;
height = size[3] * (height / size[3]);//最大限度的高
options = new QrCodeEncodingOptions
{
DisableECI = true,
CharacterSet = "UTF-8",
Width = width,
Height = height,
Margin = 0
};
writer = new BarcodeWriter();
//BarcodeFormat可以设置条码编码类型:條形碼CODE_128、二維碼QR_CODE
writer.Format = BarcodeFormat.QR_CODE;
writer.Options = options;
//options.PureBarcode = true;// 是否是纯码,如果为 false,则会在條碼下方显示数字
//生成二维码信息的内容
Bitmap bitmap = writer.Write(text + formId);
//二維碼保存文件
bitmap.Save(filePath + formId + ".png");
}
catch (Exception e)
{
throw e;
}
}