C# 生产成条形码3种方法
首先效果:

1:首先下载BarcodeLib.dll 下载地址 http://pan.baidu.com/share/link?shareid=2590968386&uk=2148890391&fid=1692834292 如果不存在了则自行搜索下载。
1.BarcodeLib.dll 一维条码库支持以下条码格式
UPC-A
UPC-E
UPC 2 Digit Ext.
UPC 5 Digit Ext.
EAN-13
JAN-13
EAN-8
ITF-14
Codabar
PostNet
Bookland/ISBN
Code 11
Code 39
Code 39 Extended
Code 93
LOGMARS
MSI
Interleaved 2 of 5
Standard 2 of 5
Code 128
Code 128-A
Code 128-B
Code 128-C
Telepen
然后项目中添加引用
- private void button6_Click(object sender, EventArgs e)
- {
- System.Drawing.Image image;
- int width = 148, height = 55;
- string fileSavePath = AppDomain.CurrentDomain.BaseDirectory + "BarcodePattern.jpg";
- if (File.Exists(fileSavePath))
- File.Delete(fileSavePath);
- GetBarcode(height, width, BarcodeLib.TYPE.CODE128, "20131025-136", out image, fileSavePath);
- pictureBox1.Image = Image.FromFile("BarcodePattern.jpg");
- }
- public static void GetBarcode(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image image, string fileSaveUrl)
- {
- try
- {
- image = null;
- BarcodeLib.Barcode b = new BarcodeLib.Barcode();
- b.BackColor = System.Drawing.Color.White;//图片背景颜色
- b.ForeColor = System.Drawing.Color.Black;//条码颜色
- b.IncludeLabel = true;
- b.Alignment = BarcodeLib.AlignmentPositions.LEFT;
- b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
- b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;//图片格式
- System.Drawing.Font font = new System.Drawing.Font("verdana", 10f);//字体设置
- b.LabelFont = font;
- b.Height = height;//图片高度设置(px单位)
- b.Width = width;//图片宽度设置(px单位)
- image = b.Encode(type, code);//生成图片
- image.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- catch (Exception ex)
- {
- image = null;
- }
- }
简单的写一下。详细的去 http://www.barcodelib.com/net_barcode/main.html 这里看。
利用 zxing.dll生成条形码和二维码 下载地址http://zxingnet.codeplex.com/
ZXing (ZebraCrossing)是一个开源的,支持多种格式的条形码图像处理库, 。使用该类库可以方便地实现二维码图像的生成和解析。
下载zxing.dll 项目参照引用
- {
- MultiFormatWriter mutiWriter = new com.google.zxing.MultiFormatWriter();
- ByteMatrix bm = mutiWriter.encode(txtMsg.Text, com.google.zxing.BarcodeFormat.QR_CODE, 300, 300);
- Bitmap img = bm.ToBitmap();
- pictureBox1.Image = img;
- //自动保存图片到当前目录
- string filename = System.Environment.CurrentDirectory + "\\QR" + DateTime.Now.Ticks.ToString() + ".jpg";
- img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
- lbshow.Text = "图片已保存到:" + filename;
- }
- catch (Exception ee)
- { MessageBox.Show(ee.Message); }

利用 QrCodeNet.dll生成条形码和二维码 下载地址http://qrcodenet.codeplex.com/
下载QrCodeNet.dll 项目参照引用
- private void button2_Click(object sender, EventArgs e)
- {
- var codeParams = CodeDescriptor.Init(ErrorCorrectionLevel.H, textBox1.Text.Trim(), QuietZoneModules.Two, 5);
- codeParams.TryEncode();
- // Render the QR code as an image
- using (var ms = new MemoryStream())
- {
- codeParams.Render(ms);
- Image image = Image.FromStream(ms);
- pictureBox1.Image = image;
- if (image != null)
- pictureBox1.SizeMode = image.Height > pictureBox1.Height ? PictureBoxSizeMode.Zoom : PictureBoxSizeMode.Normal;
- }
- }
- /// <summary>
- /// Class containing the description of the QR code and wrapping encoding and rendering.
- /// </summary>
- internal class CodeDescriptor
- {
- public ErrorCorrectionLevel Ecl;
- public string Content;
- public QuietZoneModules QuietZones;
- public int ModuleSize;
- public BitMatrix Matrix;
- public string ContentType;
- /// <summary>
- /// Parse QueryString that define the QR code properties
- /// </summary>
- /// <param name="request">HttpRequest containing HTTP GET data</param>
- /// <returns>A QR code descriptor object</returns>
- public static CodeDescriptor Init(ErrorCorrectionLevel level, string content, QuietZoneModules qzModules, int moduleSize)
- {
- var cp = new CodeDescriptor();
- //// Error correction level
- cp.Ecl = level;
- //// Code content to encode
- cp.Content = content;
- //// Size of the quiet zone
- cp.QuietZones = qzModules;
- //// Module size
- cp.ModuleSize = moduleSize;
- return cp;
- }
- /// <summary>
- /// Encode the content with desired parameters and save the generated Matrix
- /// </summary>
- /// <returns>True if the encoding succeeded, false if the content is empty or too large to fit in a QR code</returns>
- public bool TryEncode()
- {
- var encoder = new QrEncoder(Ecl);
- QrCode qr;
- if (!encoder.TryEncode(Content, out qr))
- return false;
- Matrix = qr.Matrix;
- return true;
- }
- /// <summary>
- /// Render the Matrix as a PNG image
- /// </summary>
- /// <param name="ms">MemoryStream to store the image bytes into</param>
- internal void Render(MemoryStream ms)
- {
- var render = new GraphicsRenderer(new FixedModuleSize(ModuleSize, QuietZones));
- render.WriteToStream(Matrix, System.Drawing.Imaging.ImageFormat.Png, ms);
- ContentType = "image/png";
- }
- }
效果:

参考地址:
http://www.cnblogs.com/mzlee/archive/2011/03/19/Lee_Barcode.html
http://blog.163.com/smxp_2006/blog/static/588682542010215163803/
http://q.cnblogs.com/q/15253/
http://www.csharpwin.com/csharpspace/13364r9803.shtml
http://www.2cto.com/kf/201304/203035.html
首先效果:

1:首先下载BarcodeLib.dll 下载地址 http://pan.baidu.com/share/link?shareid=2590968386&uk=2148890391&fid=1692834292 如果不存在了则自行搜索下载。
1.BarcodeLib.dll 一维条码库支持以下条码格式
UPC-A
UPC-E
UPC 2 Digit Ext.
UPC 5 Digit Ext.
EAN-13
JAN-13
EAN-8
ITF-14
Codabar
PostNet
Bookland/ISBN
Code 11
Code 39
Code 39 Extended
Code 93
LOGMARS
MSI
Interleaved 2 of 5
Standard 2 of 5
Code 128
Code 128-A
Code 128-B
Code 128-C
Telepen
然后项目中添加引用
- private void button6_Click(object sender, EventArgs e)
- {
- System.Drawing.Image image;
- int width = 148, height = 55;
- string fileSavePath = AppDomain.CurrentDomain.BaseDirectory + "BarcodePattern.jpg";
- if (File.Exists(fileSavePath))
- File.Delete(fileSavePath);
- GetBarcode(height, width, BarcodeLib.TYPE.CODE128, "20131025-136", out image, fileSavePath);
- pictureBox1.Image = Image.FromFile("BarcodePattern.jpg");
- }
- public static void GetBarcode(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image image, string fileSaveUrl)
- {
- try
- {
- image = null;
- BarcodeLib.Barcode b = new BarcodeLib.Barcode();
- b.BackColor = System.Drawing.Color.White;//图片背景颜色
- b.ForeColor = System.Drawing.Color.Black;//条码颜色
- b.IncludeLabel = true;
- b.Alignment = BarcodeLib.AlignmentPositions.LEFT;
- b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
- b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;//图片格式
- System.Drawing.Font font = new System.Drawing.Font("verdana", 10f);//字体设置
- b.LabelFont = font;
- b.Height = height;//图片高度设置(px单位)
- b.Width = width;//图片宽度设置(px单位)
- image = b.Encode(type, code);//生成图片
- image.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- catch (Exception ex)
- {
- image = null;
- }
- }
简单的写一下。详细的去 http://www.barcodelib.com/net_barcode/main.html 这里看。
利用 zxing.dll生成条形码和二维码 下载地址http://zxingnet.codeplex.com/
ZXing (ZebraCrossing)是一个开源的,支持多种格式的条形码图像处理库, 。使用该类库可以方便地实现二维码图像的生成和解析。
下载zxing.dll 项目参照引用
- {
- MultiFormatWriter mutiWriter = new com.google.zxing.MultiFormatWriter();
- ByteMatrix bm = mutiWriter.encode(txtMsg.Text, com.google.zxing.BarcodeFormat.QR_CODE, 300, 300);
- Bitmap img = bm.ToBitmap();
- pictureBox1.Image = img;
- //自动保存图片到当前目录
- string filename = System.Environment.CurrentDirectory + "\\QR" + DateTime.Now.Ticks.ToString() + ".jpg";
- img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
- lbshow.Text = "图片已保存到:" + filename;
- }
- catch (Exception ee)
- { MessageBox.Show(ee.Message); }

利用 QrCodeNet.dll生成条形码和二维码 下载地址http://qrcodenet.codeplex.com/
下载QrCodeNet.dll 项目参照引用
- private void button2_Click(object sender, EventArgs e)
- {
- var codeParams = CodeDescriptor.Init(ErrorCorrectionLevel.H, textBox1.Text.Trim(), QuietZoneModules.Two, 5);
- codeParams.TryEncode();
- // Render the QR code as an image
- using (var ms = new MemoryStream())
- {
- codeParams.Render(ms);
- Image image = Image.FromStream(ms);
- pictureBox1.Image = image;
- if (image != null)
- pictureBox1.SizeMode = image.Height > pictureBox1.Height ? PictureBoxSizeMode.Zoom : PictureBoxSizeMode.Normal;
- }
- }
- /// <summary>
- /// Class containing the description of the QR code and wrapping encoding and rendering.
- /// </summary>
- internal class CodeDescriptor
- {
- public ErrorCorrectionLevel Ecl;
- public string Content;
- public QuietZoneModules QuietZones;
- public int ModuleSize;
- public BitMatrix Matrix;
- public string ContentType;
- /// <summary>
- /// Parse QueryString that define the QR code properties
- /// </summary>
- /// <param name="request">HttpRequest containing HTTP GET data</param>
- /// <returns>A QR code descriptor object</returns>
- public static CodeDescriptor Init(ErrorCorrectionLevel level, string content, QuietZoneModules qzModules, int moduleSize)
- {
- var cp = new CodeDescriptor();
- //// Error correction level
- cp.Ecl = level;
- //// Code content to encode
- cp.Content = content;
- //// Size of the quiet zone
- cp.QuietZones = qzModules;
- //// Module size
- cp.ModuleSize = moduleSize;
- return cp;
- }
- /// <summary>
- /// Encode the content with desired parameters and save the generated Matrix
- /// </summary>
- /// <returns>True if the encoding succeeded, false if the content is empty or too large to fit in a QR code</returns>
- public bool TryEncode()
- {
- var encoder = new QrEncoder(Ecl);
- QrCode qr;
- if (!encoder.TryEncode(Content, out qr))
- return false;
- Matrix = qr.Matrix;
- return true;
- }
- /// <summary>
- /// Render the Matrix as a PNG image
- /// </summary>
- /// <param name="ms">MemoryStream to store the image bytes into</param>
- internal void Render(MemoryStream ms)
- {
- var render = new GraphicsRenderer(new FixedModuleSize(ModuleSize, QuietZones));
- render.WriteToStream(Matrix, System.Drawing.Imaging.ImageFormat.Png, ms);
- ContentType = "image/png";
- }
- }
效果:

参考地址:
http://www.cnblogs.com/mzlee/archive/2011/03/19/Lee_Barcode.html
http://blog.163.com/smxp_2006/blog/static/588682542010215163803/
http://q.cnblogs.com/q/15253/
http://www.csharpwin.com/csharpspace/13364r9803.shtml
http://www.2cto.com/kf/201304/203035.html
C# 生产成条形码3种方法的更多相关文章
- 怎样把网站js文件合并成一个?几种方法可以实现
我们在建网站时经常会用js特效代码以使页面更美观,比如js幻灯片代码.js下拉菜单等,但是网页特效一多,如果js文件没有合并的话会降低网站的性能,这时我们就要考虑合并js文件了,ytkah总结了以下几 ...
- javascript浮点数转换成整数三种方法
将浮点数转换成整数方法有很多,分享三种常用方法. Summary 暂时我就想到3个方法而已.如果读者想到其他好用方法,也可以交流一下 parseInt位运算符Math.floor Math.ceil ...
- EntityFramework嵌套查询的五种方法
这样的双where的语句应该怎么写呢: var test=MyList.Where(a => a.Flows.Where(b => b.CurrentUser == “”) 下面我就说说这 ...
- WPF编程,将控件所呈现的内容保存成图像的一种方法。
原文:WPF编程,将控件所呈现的内容保存成图像的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/detai ...
- DataTable 转换成 Json的3种方法
在web开发中,我们可能会有这样的需求,为了便于前台的JS的处理,我们需要将查询出的数据源格式比如:List<T>.DataTable转换为Json格式.特别在使用Extjs框架的时候,A ...
- 将HTML5封装成android应用APK文件的几种方法(转载)
越来越多的开发者热衷于使用html5+JavaScript开发移动Web App.不过,HTML5 Web APP的出现能否在未来取代移动应用,就目前来说,还是个未知数.一方面,用户在使用习惯上,不喜 ...
- (转) 读取xml文件转成List<T>对象的两种方法
读取xml文件,是项目中经常要用到的,所以就总结一下,最近项目中用到的读取xml文件并且转成List<T>对象的方法,加上自己知道的另一种实现方法. 就以一个简单的xml做例子. xml格 ...
- 读取xml文件转成List<T>对象的两种方法(附源码)
读取xml文件转成List<T>对象的两种方法(附源码) 读取xml文件,是项目中经常要用到的,所以就总结一下,最近项目中用到的读取xml文件并且转成List<T>对象的方法, ...
- 取xml文件转成List<T>对象的两种方法
读取xml文件转成List<T>对象的两种方法(附源码) 读取xml文件转成List<T>对象的两种方法(附源码) 读取xml文件,是项目中经常要用到的,所以就总结一下,最 ...
随机推荐
- ECMAScript6新特性之Array API
一 填充数组 var arr = new Array(5); arr.fill('abc',2,4); console.log('Array.prototype.fill',arr); // [und ...
- PAT L1-020 帅到没朋友(模拟数组)
当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为太帅而没有朋友.本题就要求你找出那些帅到没有朋友的人. 输入格式: 输入第一行给出一个正整数N(≤100),是已知朋友圈的个数:随后N行,每行首先给 ...
- git 常用命令笔记
#提交代码会加上用户名和邮箱 git config --global user.name 名字 git config --global user.email 邮箱 git config --globa ...
- 基于udp的套接字
1 ss = socket() #创建一个服务器的套接字 2 ss.bind() #绑定服务器套接字 3 inf_loop: #服务器无限循环 4 cs = ss.recvfrom()/ss.send ...
- Rendering Resources
1. Real-Time Rendering Resources http://www.realtimerendering.com/ 2. Books on Amazon http://www.ama ...
- web服务器部署过程记录
由于之前没有服务器部署经验,又选择了所有软件都是单独编译安装,遇到很多问题,解决之后还是学习到了很多新东西. 如今回过头来还是选择lnmp集成环境的部署方式比较方便快捷:https://lnmp.or ...
- 详解python2 和 python3的区别-乾颐堂
看到这个题目大家可能猜到了我接下来要讲些什么,呵呵,对了,那就是列出这两个不同版本间的却别!搜索一下大家就会知道,python有两个主要的版本,python2 和 python3 ,但是python又 ...
- 白盒静态自动化测试工具:FindBugs使用指南
目 录 1 FINDBUGS介绍 2 在ECLIPSE中安装FINDBUGS插件 3 在ECLIPSE中使用FINDBUGS操作步骤 3.1 ...
- python性能测试大致计划
hi guy: 如果注意到创建时间,那就对了.这份文章,是我学习Python一个月以后动手写的. 写下这份计划以后,只完成了第一步,其中磕磕绊绊编写代码的过程,很大一部分时间是完全用txt写的 ...
- 13.8.8 div块 居中
<div style="border:1px solid blue;width:760px; height:410px; position:absolute; left:50%; to ...