C# 利用BarcodeLib.dll生成条形码
首先效果:
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# 利用BarcodeLib.dll生成条形码的更多相关文章
- C# 利用BarcodeLib.dll生成条形码(一维,zxing,QrCodeNet/dll二维码)
原文:http://blog.csdn.net/kongwei521/article/details/17588825 首先效果: 一.下载BarcodeLib.dll 下载地址 :http://do ...
- C#利用Zxing.net生成条形码和二维码并实现打印的功能
开篇:zxing.net是.net平台下编解条形码和二维码的工具. 下载地址:http://pan.baidu.com/s/1kTr3Vuf Step1:使用VS2010新建一个窗体程序项目: ...
- python笔记 利用python 自动生成条形码 二维码
1. ean13标准条形码 from pystrich.ean13 import EAN13Encoder encode = EAN13Encoder(') encode.save('d:/barco ...
- 使用BarcodeLib.Barcode.ASP.NET生成条形码
生成条形码图片,然后在前台页面展示: <img id="img" src="Mobile/<%=url %>"/> public str ...
- C# 利用ZXing.Net来生成条形码和二维码
本文是利用ZXing.Net在WinForm中生成条形码,二维码的小例子,仅供学习分享使用,如有不足之处,还请指正. 什么是ZXing.Net? ZXing是一个开放源码的,用Java实现的多种格式的 ...
- C# 生成条形码
原文地址:http://www.cnblogs.com/xcsn/p/4514759.html 引用BarcodeLib.dll(百度云中有)生成条形 protected void Button2_C ...
- 使用html2canvas实现批量生成条形码
/*前台代码*/ <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Generat ...
- VS2010/MFC编程入门之二(利用MFC向导生成单文档应用程序框架)
VS2010/MFC编程入门之二(利用MFC向导生成单文档应用程序框架)-软件开发-鸡啄米 http://www.jizhuomi.com/software/141.html 上一讲中讲了VS20 ...
- 使用PHP-Barcode轻松生成条形码(一)
最近由于工作需要,研究了一下PHP如何生成条形码.虽然二维码时下比较流行,但是条形码依然应用广泛,不可替代.园子里有很多讲利用PHP生成条形码的文章,基本上都是围绕Barcode Bakery的,它虽 ...
随机推荐
- mvc Routing特性优化
在mvc中,Url地址是利用routing特性来支持,但是这个Routing有个问题,多个不同的地址和指向同一个action方法, 例如: http://test.com (默认) http://te ...
- c标准库中字符和数字转换的函数
字符转换为数字: #include<stdlib.h> atoi(); 将字符转换为整型 例:char ch1;int i=atoi(ch ...
- mysql的分区技术
一.概述 当 MySQL的总记录数超过了100万后,会出现性能的大幅度下降吗?答案是肯定的,但是,性 能下降>的比率不一而同,要看系统的架构.应用程序.还有>包括索引.服务器硬件等多种因素 ...
- HTML<label> 标签的 for 属性
定义和用法 for 属性规定 label 与哪个表单元素绑定. 隐式和显式的联系 标记通常以下面两种方式中的一种来和表单控件相联系:将表单控件作为标记标签的内容,这样的就是隐式形式,或者为 <l ...
- Javascript三元条件运算符
今天谈一个小知识点,三元运算符.三元运算,顾名思义会有三个要素,表达式的大致组成为condition ? expr1 : expr2:一个语句加两个表达式.问号之前为判断语句.如果为真,则执行第一个表 ...
- 开始学习requirejs+easyui的使用.
开始学习requirejs+easyui的使用. 目录结构: |-project |-easyui01 |-js |-main.js |-index.html |-libs libs目录下放入的是ea ...
- 【BZOJ3884】【降幂大法】上帝与集合的正确用法
Description 根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天, 上帝创造了一个世界的基本元素,称做“元”. 第二天, 上帝创造了一个新的元素,称作“α”.“α”被定义为“元” ...
- 对称密码-分组密码-AES
AES产生背景: DES的安全性和应用前景受到挑战,因此需要设计一个高保密性能的.算法公开的.全球免费使用的分组密码算法,用于保护敏感信息,并希望以此新算法取代DES算法,称为新一代数据加密标准,取名 ...
- bootstrap实现手风琴功能(树形列表)
首先把架包拷进项目,然后在页面中引进css,js <script src="js/jquery/jquery-2.1.1.min.js"></script> ...
- 不同版本PHP之间cURL的区别(-经验之谈)
之前在做一个采集的工具,实现采集回来的文章,图片保存起来.文章内容是保存在数据库,图片是先需要上传到图片服务器,再返回图片地址,替换掉文章的图片地址. 问题来了:都能成功采集都东西,但是,本地测试是正 ...