博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c# 生成各种标准条码实例
阅读量:4685 次
发布时间:2019-06-09

本文共 1684 字,大约阅读时间需要 5 分钟。

 最近我项目需要生成条码,那我就找了一下相关资料发现BarcodeLib来生成条码,不需要什么字体库,引用就可,写下来备我以后资料查询

using BarcodeLib;using System.IO; static System.Drawing.Image GetBarcode(int height, int width, BarcodeLib.TYPE type,string  code,out System.Drawing.Image image)        {               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.CENTER;             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);//生成图片             byte[] buffer = b.GetImageData(SaveTypes.GIF);//转换byte格式             //byte转换图片格式             MemoryStream oMemoryStream = new MemoryStream(buffer);               //設定資料流位置               oMemoryStream.Position = 0;             //return buffer;             //return image;             return System.Drawing.Image.FromStream(oMemoryStream);              }

 实例生成code128的条码

System.Drawing.Image image;            int width=500, height=100;            image= GetBarcode(height, width, BarcodeLib.TYPE.CODE128, "004320000000JN60A____1242?10.0000144300", out image);

因为本人公司禁止上传图片格式文件,无法显示最终结果

PS:本人第一次发博客,过于简陋,请大家多多包含 

附上:BarcodeLib下载地址: http://vdisk.weibo.com/s/iEw30

转载于:https://www.cnblogs.com/bao821/archive/2012/11/22/2782790.html

你可能感兴趣的文章
导出数据库指定表所有数据
查看>>
C 语言 习题 1-14
查看>>
密码锁
查看>>
Android创建与读取Excel
查看>>
AVL树-查找-插入
查看>>
Codeforces 600E Lomsat gelral(dsu on tree)
查看>>
生成验证码语法(旧版)
查看>>
优化以及bug
查看>>
Factorial Trailing Zeroes
查看>>
daomain
查看>>
C pointers和Java references 的区别
查看>>
理解MapReduce
查看>>
[Golang] GoConvey测试框架使用指南
查看>>
值类型和引用类型区别,一看就懂
查看>>
UVa 11375 Matches
查看>>
JdbcTemplate
查看>>
leetcode 2. 两数相加(Add Two Numbers)
查看>>
Crimm Imageshop 2.0 发布。
查看>>
分页存储过程
查看>>
不可忽略的知识点
查看>>