首先效果:

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

然后项目中添加引用

[csharp]  view plaincopy                 
  1. private void button6_Click(object sender, EventArgs e)
  2. {
  3. System.Drawing.Image image;
  4. int width = 148, height = 55;
  5. string fileSavePath = AppDomain.CurrentDomain.BaseDirectory + "BarcodePattern.jpg";
  6. if (File.Exists(fileSavePath))
  7. File.Delete(fileSavePath);
  8. GetBarcode(height, width, BarcodeLib.TYPE.CODE128, "20131025-136", out image, fileSavePath);
  9. pictureBox1.Image  = Image.FromFile("BarcodePattern.jpg");
  10. }
  11. public static void GetBarcode(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image image, string fileSaveUrl)
  12. {
  13. try
  14. {
  15. image = null;
  16. BarcodeLib.Barcode b = new BarcodeLib.Barcode();
  17. b.BackColor = System.Drawing.Color.White;//图片背景颜色
  18. b.ForeColor = System.Drawing.Color.Black;//条码颜色
  19. b.IncludeLabel = true;
  20. b.Alignment = BarcodeLib.AlignmentPositions.LEFT;
  21. b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
  22. b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;//图片格式
  23. System.Drawing.Font font = new System.Drawing.Font("verdana", 10f);//字体设置
  24. b.LabelFont = font;
  25. b.Height = height;//图片高度设置(px单位)
  26. b.Width = width;//图片宽度设置(px单位)
  27. image = b.Encode(type, code);//生成图片
  28. image.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
  29. }
  30. catch (Exception ex)
  31. {
  32. image = null;
  33. }
  34. }

简单的写一下。详细的去 http://www.barcodelib.com/net_barcode/main.html 这里看。

利用 zxing.dll生成条形码和二维码  下载地址http://zxingnet.codeplex.com/

ZXing (ZebraCrossing)是一个开源的,支持多种格式的条形码图像处理库, 。使用该类库可以方便地实现二维码图像的生成和解析。

下载zxing.dll 项目参照引用

[csharp]  view plaincopy                 
  1. {
  2. MultiFormatWriter mutiWriter = new com.google.zxing.MultiFormatWriter();
  3. ByteMatrix bm = mutiWriter.encode(txtMsg.Text, com.google.zxing.BarcodeFormat.QR_CODE, 300, 300);
  4. Bitmap img = bm.ToBitmap();
  5. pictureBox1.Image = img;
  6. //自动保存图片到当前目录
  7. string filename = System.Environment.CurrentDirectory + "\\QR" + DateTime.Now.Ticks.ToString() + ".jpg";
  8. img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
  9. lbshow.Text = "图片已保存到:" + filename;
  10. }
  11. catch (Exception ee)
  12. { MessageBox.Show(ee.Message); }

利用 QrCodeNet.dll生成条形码和二维码  下载地址http://qrcodenet.codeplex.com/

下载QrCodeNet.dll 项目参照引用

[csharp]  view plaincopy                 
  1. private void button2_Click(object sender, EventArgs e)
  2. {
  3. var codeParams = CodeDescriptor.Init(ErrorCorrectionLevel.H, textBox1.Text.Trim(), QuietZoneModules.Two, 5);
  4. codeParams.TryEncode();
  5. // Render the QR code as an image
  6. using (var ms = new MemoryStream())
  7. {
  8. codeParams.Render(ms);
  9. Image image = Image.FromStream(ms);
  10. pictureBox1.Image = image;
  11. if (image != null)
  12. pictureBox1.SizeMode = image.Height > pictureBox1.Height ? PictureBoxSizeMode.Zoom : PictureBoxSizeMode.Normal;
  13. }
  14. }
  15. /// <summary>
  16. /// Class containing the description of the QR code and wrapping encoding and rendering.
  17. /// </summary>
  18. internal class CodeDescriptor
  19. {
  20. public ErrorCorrectionLevel Ecl;
  21. public string Content;
  22. public QuietZoneModules QuietZones;
  23. public int ModuleSize;
  24. public BitMatrix Matrix;
  25. public string ContentType;
  26. /// <summary>
  27. /// Parse QueryString that define the QR code properties
  28. /// </summary>
  29. /// <param name="request">HttpRequest containing HTTP GET data</param>
  30. /// <returns>A QR code descriptor object</returns>
  31. public static CodeDescriptor Init(ErrorCorrectionLevel level, string content, QuietZoneModules qzModules, int moduleSize)
  32. {
  33. var cp = new CodeDescriptor();
  34. //// Error correction level
  35. cp.Ecl = level;
  36. //// Code content to encode
  37. cp.Content = content;
  38. //// Size of the quiet zone
  39. cp.QuietZones = qzModules;
  40. //// Module size
  41. cp.ModuleSize = moduleSize;
  42. return cp;
  43. }
  44. /// <summary>
  45. /// Encode the content with desired parameters and save the generated Matrix
  46. /// </summary>
  47. /// <returns>True if the encoding succeeded, false if the content is empty or too large to fit in a QR code</returns>
  48. public bool TryEncode()
  49. {
  50. var encoder = new QrEncoder(Ecl);
  51. QrCode qr;
  52. if (!encoder.TryEncode(Content, out qr))
  53. return false;
  54. Matrix = qr.Matrix;
  55. return true;
  56. }
  57. /// <summary>
  58. /// Render the Matrix as a PNG image
  59. /// </summary>
  60. /// <param name="ms">MemoryStream to store the image bytes into</param>
  61. internal void Render(MemoryStream ms)
  62. {
  63. var render = new GraphicsRenderer(new FixedModuleSize(ModuleSize, QuietZones));
  64. render.WriteToStream(Matrix, System.Drawing.Imaging.ImageFormat.Png, ms);
  65. ContentType = "image/png";
  66. }
  67. }

效果:

参考地址:

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

然后项目中添加引用

[csharp]  view plaincopy                 
  1. private void button6_Click(object sender, EventArgs e)
  2. {
  3. System.Drawing.Image image;
  4. int width = 148, height = 55;
  5. string fileSavePath = AppDomain.CurrentDomain.BaseDirectory + "BarcodePattern.jpg";
  6. if (File.Exists(fileSavePath))
  7. File.Delete(fileSavePath);
  8. GetBarcode(height, width, BarcodeLib.TYPE.CODE128, "20131025-136", out image, fileSavePath);
  9. pictureBox1.Image  = Image.FromFile("BarcodePattern.jpg");
  10. }
  11. public static void GetBarcode(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image image, string fileSaveUrl)
  12. {
  13. try
  14. {
  15. image = null;
  16. BarcodeLib.Barcode b = new BarcodeLib.Barcode();
  17. b.BackColor = System.Drawing.Color.White;//图片背景颜色
  18. b.ForeColor = System.Drawing.Color.Black;//条码颜色
  19. b.IncludeLabel = true;
  20. b.Alignment = BarcodeLib.AlignmentPositions.LEFT;
  21. b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
  22. b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;//图片格式
  23. System.Drawing.Font font = new System.Drawing.Font("verdana", 10f);//字体设置
  24. b.LabelFont = font;
  25. b.Height = height;//图片高度设置(px单位)
  26. b.Width = width;//图片宽度设置(px单位)
  27. image = b.Encode(type, code);//生成图片
  28. image.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
  29. }
  30. catch (Exception ex)
  31. {
  32. image = null;
  33. }
  34. }

简单的写一下。详细的去 http://www.barcodelib.com/net_barcode/main.html 这里看。

利用 zxing.dll生成条形码和二维码  下载地址http://zxingnet.codeplex.com/

ZXing (ZebraCrossing)是一个开源的,支持多种格式的条形码图像处理库, 。使用该类库可以方便地实现二维码图像的生成和解析。

下载zxing.dll 项目参照引用

[csharp]  view plaincopy                 
  1. {
  2. MultiFormatWriter mutiWriter = new com.google.zxing.MultiFormatWriter();
  3. ByteMatrix bm = mutiWriter.encode(txtMsg.Text, com.google.zxing.BarcodeFormat.QR_CODE, 300, 300);
  4. Bitmap img = bm.ToBitmap();
  5. pictureBox1.Image = img;
  6. //自动保存图片到当前目录
  7. string filename = System.Environment.CurrentDirectory + "\\QR" + DateTime.Now.Ticks.ToString() + ".jpg";
  8. img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
  9. lbshow.Text = "图片已保存到:" + filename;
  10. }
  11. catch (Exception ee)
  12. { MessageBox.Show(ee.Message); }

利用 QrCodeNet.dll生成条形码和二维码  下载地址http://qrcodenet.codeplex.com/

下载QrCodeNet.dll 项目参照引用

[csharp]  view plaincopy                 
  1. private void button2_Click(object sender, EventArgs e)
  2. {
  3. var codeParams = CodeDescriptor.Init(ErrorCorrectionLevel.H, textBox1.Text.Trim(), QuietZoneModules.Two, 5);
  4. codeParams.TryEncode();
  5. // Render the QR code as an image
  6. using (var ms = new MemoryStream())
  7. {
  8. codeParams.Render(ms);
  9. Image image = Image.FromStream(ms);
  10. pictureBox1.Image = image;
  11. if (image != null)
  12. pictureBox1.SizeMode = image.Height > pictureBox1.Height ? PictureBoxSizeMode.Zoom : PictureBoxSizeMode.Normal;
  13. }
  14. }
  15. /// <summary>
  16. /// Class containing the description of the QR code and wrapping encoding and rendering.
  17. /// </summary>
  18. internal class CodeDescriptor
  19. {
  20. public ErrorCorrectionLevel Ecl;
  21. public string Content;
  22. public QuietZoneModules QuietZones;
  23. public int ModuleSize;
  24. public BitMatrix Matrix;
  25. public string ContentType;
  26. /// <summary>
  27. /// Parse QueryString that define the QR code properties
  28. /// </summary>
  29. /// <param name="request">HttpRequest containing HTTP GET data</param>
  30. /// <returns>A QR code descriptor object</returns>
  31. public static CodeDescriptor Init(ErrorCorrectionLevel level, string content, QuietZoneModules qzModules, int moduleSize)
  32. {
  33. var cp = new CodeDescriptor();
  34. //// Error correction level
  35. cp.Ecl = level;
  36. //// Code content to encode
  37. cp.Content = content;
  38. //// Size of the quiet zone
  39. cp.QuietZones = qzModules;
  40. //// Module size
  41. cp.ModuleSize = moduleSize;
  42. return cp;
  43. }
  44. /// <summary>
  45. /// Encode the content with desired parameters and save the generated Matrix
  46. /// </summary>
  47. /// <returns>True if the encoding succeeded, false if the content is empty or too large to fit in a QR code</returns>
  48. public bool TryEncode()
  49. {
  50. var encoder = new QrEncoder(Ecl);
  51. QrCode qr;
  52. if (!encoder.TryEncode(Content, out qr))
  53. return false;
  54. Matrix = qr.Matrix;
  55. return true;
  56. }
  57. /// <summary>
  58. /// Render the Matrix as a PNG image
  59. /// </summary>
  60. /// <param name="ms">MemoryStream to store the image bytes into</param>
  61. internal void Render(MemoryStream ms)
  62. {
  63. var render = new GraphicsRenderer(new FixedModuleSize(ModuleSize, QuietZones));
  64. render.WriteToStream(Matrix, System.Drawing.Imaging.ImageFormat.Png, ms);
  65. ContentType = "image/png";
  66. }
  67. }

效果:

参考地址:

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种方法的更多相关文章

  1. 怎样把网站js文件合并成一个?几种方法可以实现

    我们在建网站时经常会用js特效代码以使页面更美观,比如js幻灯片代码.js下拉菜单等,但是网页特效一多,如果js文件没有合并的话会降低网站的性能,这时我们就要考虑合并js文件了,ytkah总结了以下几 ...

  2. javascript浮点数转换成整数三种方法

    将浮点数转换成整数方法有很多,分享三种常用方法. Summary 暂时我就想到3个方法而已.如果读者想到其他好用方法,也可以交流一下 parseInt位运算符Math.floor Math.ceil ...

  3. EntityFramework嵌套查询的五种方法

    这样的双where的语句应该怎么写呢: var test=MyList.Where(a => a.Flows.Where(b => b.CurrentUser == “”) 下面我就说说这 ...

  4. WPF编程,将控件所呈现的内容保存成图像的一种方法。

    原文:WPF编程,将控件所呈现的内容保存成图像的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/detai ...

  5. DataTable 转换成 Json的3种方法

    在web开发中,我们可能会有这样的需求,为了便于前台的JS的处理,我们需要将查询出的数据源格式比如:List<T>.DataTable转换为Json格式.特别在使用Extjs框架的时候,A ...

  6. 将HTML5封装成android应用APK文件的几种方法(转载)

    越来越多的开发者热衷于使用html5+JavaScript开发移动Web App.不过,HTML5 Web APP的出现能否在未来取代移动应用,就目前来说,还是个未知数.一方面,用户在使用习惯上,不喜 ...

  7. (转) 读取xml文件转成List<T>对象的两种方法

    读取xml文件,是项目中经常要用到的,所以就总结一下,最近项目中用到的读取xml文件并且转成List<T>对象的方法,加上自己知道的另一种实现方法. 就以一个简单的xml做例子. xml格 ...

  8. 读取xml文件转成List<T>对象的两种方法(附源码)

    读取xml文件转成List<T>对象的两种方法(附源码) 读取xml文件,是项目中经常要用到的,所以就总结一下,最近项目中用到的读取xml文件并且转成List<T>对象的方法, ...

  9. 取xml文件转成List<T>对象的两种方法

    读取xml文件转成List<T>对象的两种方法(附源码)   读取xml文件转成List<T>对象的两种方法(附源码) 读取xml文件,是项目中经常要用到的,所以就总结一下,最 ...

随机推荐

  1. python的paramiko模块简单应用

    用法1,SSHClient 分别可以使用密码和秘钥登陆,然后执行命令,并且获取执行结果 import paramiko #创建一个SSH对象 ssh = paramiko.SSHClient() #允 ...

  2. 安装运行Rovio

    https://github.com/ethz-asl/rovio下载代码,该存储库包含ROVIO(Robust Visual Inertial Odometry)框架. https://github ...

  3. linux 下 php 安装 Gearman

    Gearman是一个分发任务的程序框架,它会对作业进行排队自动分配到一系列机器上.gearman跨语言跨平台,很方便的实现异步后台任务.   一个Gearman请求的处理过程涉及三个角色: Clien ...

  4. 安全运维 -- 更改ssh端口

    环境:Ubuntu 16 前言 黑客遍地都是,ssh/pop3/ftp等爆破工具的流行让站长的日常运维工作量大大加重.Metasplot,Bruter等工具更是针对以上协议有专门 的破解方法,有字典破 ...

  5. PAT 1058 选择题(20)(代码+思路)

    1058 选择题(20 分) 批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多. 输入格式: 输入在第一行给出两个正整数 N(≤ 1000)和 M(≤ 100 ...

  6. web服务器部署过程记录

    由于之前没有服务器部署经验,又选择了所有软件都是单独编译安装,遇到很多问题,解决之后还是学习到了很多新东西. 如今回过头来还是选择lnmp集成环境的部署方式比较方便快捷:https://lnmp.or ...

  7. vc到vs2015消息函数

    afx_msg LRESULT OnMyIconNotify(WPARAM wParam,LPARAM lParam); vc6 可以是void  vs2015不可以 ON_MESSAGE(MYWM_ ...

  8. 如何从dvi生成pdf--------亲测有效果.

    用里面第二个命令. http://blog.csdn.net/u014682350/article/details/46482477

  9. QQ使用技巧

    1.改变真实地理位置 大家知道,现在很多QQ都是显示IP和地理位置的版本,这样一来,自己的位置就暴露了.其实想隐藏自己的位置也简单,只要用代理服务器就是了.不要把它看成很复杂的东西,建议去下载&quo ...

  10. ORACLE 查看分区表分区大小

    SELECT *  FROM dba_segments t WHERE t.segment_name ='table_name'; pratition_name : 分区名 bytes : 分区大小( ...