首先效果:

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

然后项目中添加引用

  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 项目参照引用

  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 项目参照引用

  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# 利用BarcodeLib.dll生成条形码的更多相关文章

  1. C# 利用BarcodeLib.dll生成条形码(一维,zxing,QrCodeNet/dll二维码)

    原文:http://blog.csdn.net/kongwei521/article/details/17588825 首先效果: 一.下载BarcodeLib.dll 下载地址 :http://do ...

  2. C#利用Zxing.net生成条形码和二维码并实现打印的功能

        开篇:zxing.net是.net平台下编解条形码和二维码的工具. 下载地址:http://pan.baidu.com/s/1kTr3Vuf Step1:使用VS2010新建一个窗体程序项目: ...

  3. python笔记 利用python 自动生成条形码 二维码

    1. ean13标准条形码 from pystrich.ean13 import EAN13Encoder encode = EAN13Encoder(') encode.save('d:/barco ...

  4. 使用BarcodeLib.Barcode.ASP.NET生成条形码

    生成条形码图片,然后在前台页面展示: <img id="img" src="Mobile/<%=url %>"/> public str ...

  5. C# 利用ZXing.Net来生成条形码和二维码

    本文是利用ZXing.Net在WinForm中生成条形码,二维码的小例子,仅供学习分享使用,如有不足之处,还请指正. 什么是ZXing.Net? ZXing是一个开放源码的,用Java实现的多种格式的 ...

  6. C# 生成条形码

    原文地址:http://www.cnblogs.com/xcsn/p/4514759.html 引用BarcodeLib.dll(百度云中有)生成条形 protected void Button2_C ...

  7. 使用html2canvas实现批量生成条形码

    /*前台代码*/ <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Generat ...

  8. VS2010/MFC编程入门之二(利用MFC向导生成单文档应用程序框架)

    VS2010/MFC编程入门之二(利用MFC向导生成单文档应用程序框架)-软件开发-鸡啄米 http://www.jizhuomi.com/software/141.html   上一讲中讲了VS20 ...

  9. 使用PHP-Barcode轻松生成条形码(一)

    最近由于工作需要,研究了一下PHP如何生成条形码.虽然二维码时下比较流行,但是条形码依然应用广泛,不可替代.园子里有很多讲利用PHP生成条形码的文章,基本上都是围绕Barcode Bakery的,它虽 ...

随机推荐

  1. SetTimer的使用

    SetTimer函数用于创建一个计时器,KillTimer函数用于销毁一个计时器.计时器属于系统资源,使用完应及时销毁. SetTimer的函数原型如下:UINT_PTR SetTimer( HWND ...

  2. ArcGIS Runtime SDK for WPF已不更新,后续将被ArcGIS Runtime SDK for .NET取代

    ArcGIS Runtime SDK 10.2.5 for WPF is now available! by mbranscomb and Rex Hansen on January 27, 2015 ...

  3. ios专题 - 图片(UIImage)获取方法

    说到图片获取的方法,就得看API文档. UIImage生成实例的方法有: 1)imageNamed 从指定文件返回对象. 这个方法有个比较特殊的地方:该方法首先从系统缓存中寻找该图片,如果有,则从缓存 ...

  4. [转]:移动端H5页面高清多屏适配方案

    原文链接:http://www.tuicool.com/articles/YJviea 背景 开发移动端H5页面 面对不同分辨率的手机 面对不同屏幕尺寸的手机 视觉稿 在前端开发之前,视觉MM会给我们 ...

  5. sublime_2014-11-19

    http://xionggang163.blog.163.com/blog/static/376538322013930104310297/ 直接输入注册码就可以了 ----- BEGIN LICEN ...

  6. Splay tree

    类别:二叉排序树 空间效率:O(n) 时间效率:O(log n)内完成插入.查找.删除操作 创造者:Daniel Sleator和Robert Tarjan 优点:每次查询会调整树的结构,使被查询频率 ...

  7. 暑假集训(2)第九弹 ----- Points on Cycle(hdu1700)

                                                Points on Cycle Time Limit:1000MS     Memory Limit:32768 ...

  8. 《sort命令的k选项大讨论》-linux命令五分钟系列之二十七

    本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...

  9. ps -aux

    ~]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.2 2900 852 ? Ss 11:49 ...

  10. 常用的工具GCC GDB Make Makefile

    系统调用系统调用是操作系统提供给外部应用程序的一组特殊的接口.应用程序通过这组特殊“接口”来获得操作系统内核提供的服务.在 C 语言中,操作系统的系统调用通常通过函数调用的形式完成, 这是因为这些函数 ...