.net 制作二维码

.net 制作二维码

首先  要下载  ThoughtWorks.QRCode.dll

下载地址:http://download.csdn.net/detail/lybwwp/6861821

然后新建项目 把ThoughtWorks.QRCode.dll 文件 加入到项目中 添加项目引用

前台

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>CodeIndex</title>
<script src="~/Scripts/jquery.min.js"></script>
<script type="text/javascript">
function Code() {
var txt=$("#TxtInfo").val();
$.post("/Code/Text", { "Txt": txt }, function (data) {
$("#imgcode").attr("src",data);
})
}
</script>

</head>
<body>
<div>
<img id="imgcode" style="border:dashed;width:190px;height:190px"/><br><br>
<input type="text" id="TxtInfo" style="width:190px"/>&nbsp;&nbsp;
<input type="button" value="编 码" onclick="Code()"/>
</div>
</body>
</html>

------

using System.Text;
using ThoughtWorks;
using ThoughtWorks.QRCode;
using ThoughtWorks.QRCode.Codec;
using ThoughtWorks.QRCode.Codec.Data;
using System.Drawing;

public ActionResult CodeIndex()
{
return View();
}

public string Text(string Txt)
{
Bitmap btp;
string enCodeString = Txt;
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
btp = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8);
string filename = DateTime.Now.ToString("yyyymmddhhmmss");
string path = Server.MapPath("~/image/") + filename + ".jpg";
btp.Save(path);
string imgpath = "/image/" + filename + ".jpg";
return imgpath;
}

注意 还要在文件中建立一个存储二维码的文件夹 image

上一篇:C# list 筛选FindAll


下一篇:The median of multi ascending array