public class QRcode
{
//检测是否存在二维码(不存在则生成)
public static void CheckCode(string nr, string url, string fileName)
{
try
{
var uploadFolder = HttpContext.Current.Server.MapPath(url);
string filepath = uploadFolder + fileName;
FileInfo fi = new FileInfo(filepath);
if (!fi.Exists)
{
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
qrCodeEncoder.QRCodeScale = 4;
qrCodeEncoder.QRCodeVersion = 7;
qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
System.Drawing.Image image = qrCodeEncoder.Encode(nr);
image = new Bitmap(image, 1280, 1280);
if (!Directory.Exists(uploadFolder))
{
Directory.CreateDirectory(uploadFolder);
}
System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
fs.Close();
image.Dispose();
}
}
catch
{
return;
}
}
}
生成并保存二维码
最新推荐文章于 2024-01-17 14:14:29 发布