C# 利用BarcodeLib.dll生成条形码(一维,zxing,QrCodeNet/dll二维码)
原文:http://blog.csdn.net/kongwei521/article/details/17588825
首先效果:
一、下载BarcodeLib.dll
下载地址 :http://download.csdn.net/detail/lllooollpp/7961715
源码:https://github.com/hjgode/barcodeLib
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 = , height = ;
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;//code的显示位置
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, , );
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, ); 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生成条形码(一维,zxing,QrCodeNet/dll二维码)的更多相关文章
- java二维码生成-谷歌(Google.zxing)开源二维码生成学习及实例
java二维码生成-谷歌(Google.zxing)开源二维码生成的实例及介绍 我们使用比特矩阵(位矩阵)的QR码编码在缓冲图片上画出二维码 实例有以下一个传入参数 OutputStream ou ...
- TP框架中生成带背景带文字的二维码
首先下载一个phpqrcode的包放到/vendor目录下 链接:https://pan.baidu.com/s/18jV9DypYB_PHDhD6C0iedQ 提取码:qxuo 如果只是单纯生成二维 ...
- C#利用zxing.net操作二维码和条形码
下载地址:http://zxingnet.codeplex.com/ zxing.net是.net平台下编解条形码和二维码的工具,使用非常方便. 首先下载二进制dll文件,引入工程: 代码: usin ...
- 生成二维码、条形码、带logo的二维码
Nuget安装ZXing.Net,帮助类: using System; using System.Collections.Generic; using System.Drawing; using Sy ...
- 使用zxing生成彩色或带图片的二维码
<!-- https://mvnrepository.com/artifact/com.google.zxing/core --> <dependency> <group ...
- 使用zxing编写的二维码生成解析工具:QRCoder
zxing GitHub地址 QRCoder GitHub地址 TipDialog.java package com.wolf_pan; import java.util.Timer; import ...
- 利用phpqrcode二维码生成类库合成带logo的二维码并且用合成的二维码生成海报(二)
前期准备 引入phpqrcode类库(下载地址:https://download.csdn.net/download/weixin_37557729/11891240:支持彩色二维码的下载地址:htt ...
- Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果
Android 高手进阶(21) 版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明出处:http://blog.csdn.net/xiaanming/article/detail ...
- 【转】Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果--不错
原文网址:http://blog.csdn.net/xiaanming/article/details/10163203 转载请注明出处:http://blog.csdn.net/xiaanming/ ...
- 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果(转)
转载:http://blog.csdn.net/xiaanming/article/details/10163203 了解二维码这个东西还是从微信 中,当时微信推出二维码扫描功能,自己感觉挺新颖的,从 ...
随机推荐
- arcgis andriod 长按获得当前信息
// 长按显示鼠标点坐标及比例尺 private class myLongPressListener implements OnLongPressListener { private static f ...
- Java反射中的getClass()方法
Java反射学习 所谓反射,可以理解为在运行时期获取对象类型信息的操作.传统的编程方法要求程序员在编译阶段决定使用的类型,但是在反射的帮助下,编程人员可以动态获取这些信息,从而编写更加具有可移植性的代 ...
- CocoaPods 添加第三方库报错
1.终端报错:The dependency MBProgressHUD (~> 0.9.2) is not used in any concrete target.2.原因:CocoaPods升 ...
- IOS 杂笔-19(属性与变量的优缺点)
IOS 杂笔-19(属性与变量的优缺点) 在前面的文章中我介绍了属性与变量的区别.这篇博客我将会简单介绍一下属性与变量的优缺点. 变量 优点: 访问速度快 缺点: 使用不灵活 属性 缺点: 耗时 优点 ...
- 蓝牙防丢器原理、实现与Android BLE接口编程
本文是对已实现的蓝牙防丢器项目的总结,阐述蓝牙防丢器的原理.实现与android客户端的蓝牙BLE接口编程.在这里重点关注如何利用BLE接口来进行工程实现,对于BLE的协议.涉及到JNI的BLE接口内 ...
- IOS设计模式-备忘录模式
内容大纲 如何存储记录 备忘录模式的基本原理 使用备忘录模式 优化存储方案 恢复UIView的状态 1.如何存储记录 在存储记录时,第一步我们需要用一把钥匙去打开一把锁.第二步,当我们打开锁之后就会有 ...
- iOS之学习资源收集--很好的IOS技术学习网站
点击图片也能打开相关的网站: https://boxueio.com/skill/swift http://ios.b2mp.cn/ http://gold.xitu.io/welcome/?utm_ ...
- Tomcat服务器性能优化
在这篇文章里分以下的七个步骤,按照这些步骤走,Tomcat服务器的性能就能改善哦. 增加JVM堆(heap) 解决内存泄漏问题 线程池(thread pool)的设置 压缩 调节数据库性能 Tomca ...
- Monyer.cn黑客小游戏
花了一天的时间,Monyer给大家带来了一个有趣的东东——拥有15个关卡的黑客小游戏. 入口http://monyer.com/game/game1 因为一直以来都是大家跟我一起学习网络技术嘛,所以这 ...
- Android 实用代码片段
一些不常见确又很实用的代码块. 1.精确获取屏幕尺寸(例如:3.5.4.0.5.0寸屏幕) public static double getScreenPhysicalSize(Activity ct ...