asp.net(C#)利用QRCode生成二维码
程序员文章站
2023-09-19 22:07:25
aspx.cs" Inherits="QRCode" %>
生成二维码
请输入内容:...
aspx.cs" Inherits="QRCode" %> 生成二维码请输入内容:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class QRCode : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string CodeText = TextBox1.Text.Trim(); if (!string.IsNullOrEmpty(CodeText)) { ImageCode.Visible = true; ImageCode.ImageUrl = "GetQRCode.ashx?CodeText=" + CodeText; } } }
using System; using System.Web; using ThoughtWorks.QRCode.Codec; using ThoughtWorks.QRCode.Codec.Data; using ThoughtWorks.QRCode.Codec.Util; using System.IO; using System.Text; public class GetQRCode : IHttpHandler { public void ProcessRequest (HttpContext context) { String data = context.Request["CodeText"]; if (!string.IsNullOrEmpty(data)) { QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; qrCodeEncoder.QRCodeScale = 4; qrCodeEncoder.QRCodeVersion = 8; qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; System.Drawing.Bitmap image = qrCodeEncoder.Encode(data); System.IO.MemoryStream MStream = new System.IO.MemoryStream(); image.Save(MStream, System.Drawing.Imaging.ImageFormat.Png); context.Response.ClearContent(); context.Response.ContentType = "image/Png"; context.Response.BinaryWrite(MStream.ToArray()); } context.Response.Flush(); context.Response.End(); } public bool IsReusable { get { return false; } } }
推荐阅读
-
利用phpqrcode二维码生成类库和imagecopymerge函数制拼接图片的经验(一)
-
利用phpqrcode二维码生成类库合成带logo的二维码并且用合成的二维码生成海报(二)
-
详解ASP.NET MVC 利用Razor引擎生成静态页
-
asp.net(C#)利用QRCode生成二维码
-
利用jquery.qrcode在页面上生成二维码且支持中文
-
QRCode.js二维码生成并能长按识别
-
ASP.NET实现二维码(QRCode)的创建和读取
-
C# winform点击生成二维码实例代码
-
Python二维码生成库qrcode安装和使用示例
-
Asp.Net Core 生成二维码(NuGet使用QRCoder)