ASP.NET生成二维码
类别:编程学习 浏览量:800
时间:2014-8-1 ASP.NET生成二维码
ASP.NET生成二维码下面使用ThoughtWorks.QRCode.dll这个类库,实现生成二维码
使用时需要增加:下面三个命名空间
using ThoughtWorks.QRCode.Codec;
using ThoughtWorks.QRCode.Codec.Data;
using ThoughtWorks.QRCode.Codec.Util;
下面代码主要是在asp.net中,生成一张二维码图片,在网页中显示,而且,将二维码图片保存在了,D:\zlf\zz。png;
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing.Imaging;
using ThoughtWorks.QRCode.Codec;
using ThoughtWorks.QRCode.Codec.Data;
using ThoughtWorks.QRCode.Codec.Util;
using System.IO;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
qrCodeEncoder.QRCodeScale = 4;
qrCodeEncoder.QRCodeVersion = 8;
qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
//String data = "Hello 二维码!";
String data = TextBox1.Text.ToString();
Response.Write(data);
System.Drawing.Bitmap image = qrCodeEncoder.Encode(data);
System.IO.MemoryStream MStream = new System.IO.MemoryStream();
image.Save(MStream, System.Drawing.Imaging.ImageFormat.Png);
Response.ClearContent();
Response.ContentType = "image/Png";
Response.BinaryWrite(MStream.ToArray());
//FileInfo f = new FileInfo(@"d:\\zl.png");
Directory.CreateDirectory("d:\\\\zlf");
FileStream fs = new FileStream("d:\\\\zlf\\\\zz。png", FileMode.CreateNew, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs, UTF8Encoding.UTF8);
byte[] by = MStream.ToArray();
for (int i = 0; i < MStream.ToArray().Length; i++)
bw.Write(by[i]);
fs.Close();
}
}
aspx页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<html>
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<li>
请输入内容:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br/>
<asp:Button ID="Button1" runat="server" Text="生成二维码" onclick="Button1_Click" />
</li>
</form>
</body>
</html>
您可能感兴趣
- asp.net中fileupload上传文件的方法
- ASP.NET将Excel数据导入到数据库
- ASP.NET抓取网页内容
- asp.net 消息队列
- asp.net小数点四舍五入
- ASP.NET参数化查询
- ASP.NET常用加密解密方法
- Asp.net导出Excel乱码
- ASP.NET Web API中参数的传递
- asp.net 参数化like模糊查询
- ASP.NET全角与半角相互转换
- asp.net中split的用法
- ASP.NET中Obsolete属性
- Asp.net操作Word文档
- ASP.NET mvc异常处理的方法
- asp.net中使用ueditor
- 鞠婧祎和杨紫两种风格的女生,你心里谁比较美(鞠婧祎和杨紫两种风格的女生)
- 三千年第一美女鞠婧祎出演白素贞pk杨紫,颜值胜赵雅芝王祖贤(三千年第一美女鞠婧祎出演白素贞pk杨紫)
- 成都轨道交通13号线一期工程最新进展(成都轨道交通13号线一期工程最新进展)
- 越南没事(越南没事情做)
- 重庆旅游攻略(重庆旅游3-4天攻略最佳线路)
- 周杰伦演唱会门票(周杰伦演唱会门票多少钱一张2023)