码迷,mamicode.com
首页 > Windows程序 > 详细

C#通过第三方组件生成二维码(QR Code)和条形码(Bar Code)

时间:2018-01-10 11:50:19      阅读:395      评论:0      收藏:0      [点我收藏+]

标签:write   eric   blog   void   tty   str   版本   style   描述   

 

方法很多,可以参考以下几种方案,就不展开,地址如下:

https://www.cnblogs.com/mingmingruyuedlut/p/6120671.html

 

这里描述的,是某项目需求,在网页中输出为图片并展示,代码如下:

using ThoughtWorks.QRCode.Codec;

 

public void ProcessRequest(HttpContext context)
{

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();

//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();*/

}

 

 this.Image1.ImageUrl = "/TextBuilder.ashx?OrderNo=" + Ti_NO;

 

附上此种QrCode使用方法

 

C#通过第三方组件生成二维码(QR Code)和条形码(Bar Code)

标签:write   eric   blog   void   tty   str   版本   style   描述   

原文地址:https://www.cnblogs.com/guoqiang1/p/8256909.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!