64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
|
using System;
|
|||
|
using System.IO;
|
|||
|
using System.Text;
|
|||
|
using ThoughtWorks.QRCode.Codec;
|
|||
|
using System.Web.UI;
|
|||
|
|
|||
|
namespace BLL
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 上传附件相关
|
|||
|
/// </summary>
|
|||
|
public class CreateQRCodeService
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 生成二维码方法一
|
|||
|
/// </summary>
|
|||
|
public static string CreateCode_Simple(string nr)
|
|||
|
{
|
|||
|
string imageUrl = string.Empty;
|
|||
|
if (!string.IsNullOrEmpty(nr))
|
|||
|
{
|
|||
|
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder
|
|||
|
{
|
|||
|
QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE,
|
|||
|
QRCodeScale = nr.Length,
|
|||
|
QRCodeVersion = 0,
|
|||
|
QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M
|
|||
|
};
|
|||
|
System.Drawing.Image image = qrCodeEncoder.Encode(nr, Encoding.UTF8);
|
|||
|
string filepath = UploadFileService.QRCodeImageFilePath;
|
|||
|
var getStr = Funs.GetStrListByStr(nr, '$');
|
|||
|
if (getStr.Count > 0)
|
|||
|
{
|
|||
|
filepath += getStr[0].ToString() + "\\";
|
|||
|
}
|
|||
|
filepath += DateTime.Now.ToString("yyyyMMdd").ToString() + "\\";
|
|||
|
|
|||
|
string ALLPath = Funs.RootPath + filepath;
|
|||
|
//如果文件夹不存在,则创建
|
|||
|
if (!Directory.Exists(ALLPath))
|
|||
|
{
|
|||
|
Directory.CreateDirectory(ALLPath);
|
|||
|
}
|
|||
|
string filename = DateTime.Now.ToString("yyyyMMddhhmmssfff").ToString() + ".jpg";
|
|||
|
FileStream fs = new FileStream(ALLPath + filename, FileMode.OpenOrCreate, FileAccess.Write);
|
|||
|
image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|||
|
fs.Close();
|
|||
|
image.Dispose();
|
|||
|
imageUrl= filepath + filename;
|
|||
|
}
|
|||
|
return imageUrl;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public static bool isHaveImage(string url)
|
|||
|
{
|
|||
|
string filepath = Funs.RootPath + url;
|
|||
|
return File.Exists(filepath);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|