方法不少,能夠參考如下幾種方案,就不展開,地址以下:html
https://www.cnblogs.com/mingmingruyuedlut/p/6120671.htmlui
這裏描述的,是某項目需求,在網頁中輸出爲圖片並展現,代碼以下:this
using ThoughtWorks.QRCode.Codec;編碼
public void ProcessRequest(HttpContext context)
{url
context.Response.ContentType = "text/plain";
string OrderNo = context.Request.Params["OrderNo"];
QRCodeEncoder encoder = new QRCodeEncoder();
encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;//編碼方式(注意:BYTE能支持中文,ALPHA_NUMERIC掃描出來的都是數字)
encoder.QRCodeScale = 6;//大小(值越大生成的二維碼圖片像素越高)
encoder.QRCodeVersion = 0;//版本(注意:設置爲0主要是防止編碼的字符串太長時發生錯誤)
encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;//錯誤效驗、錯誤更正(有4個等級)
//encoder.QRCodeBackgroundColor = Color.Yellow;
//encoder.QRCodeForegroundColor = Color.Green;
System.Drawing.Image _CodeImage = encoder.Encode(OrderNo);
System.IO.MemoryStream _Stream = new System.IO.MemoryStream();
_CodeImage.Save(_Stream, System.Drawing.Imaging.ImageFormat.Jpeg);
context.Response.ContentType = "image/tiff";
context.Response.Clear();
context.Response.BufferOutput = true;
context.Response.BinaryWrite(_Stream.GetBuffer());
context.Response.Flush();
spa
//39碼生成部分,屏蔽
/*context.Response.ContentType = "text/plain";
string OrderNo = context.Request.Params["OrderNo"];
WebApplication1.Code39 _Code39 = new Code39();
_Code39.Height = 60;
_Code39.Magnify = 0;
_Code39.ViewFont = new Font("Arial", 12);
System.Drawing.Image _CodeImage = _Code39.GetCodeImage(OrderNo, Code39.Code39Model.Code39Normal, true);
System.IO.MemoryStream _Stream = new System.IO.MemoryStream();
_CodeImage.Save(_Stream, System.Drawing.Imaging.ImageFormat.Jpeg);
context.Response.ContentType = "image/tiff";
context.Response.Clear();
context.Response.BufferOutput = true;
context.Response.BinaryWrite(_Stream.GetBuffer());
context.Response.Flush();*/.net
}code
this.Image1.ImageUrl = "/TextBuilder.ashx?OrderNo=" + Ti_NO;orm