c# 生成各种标准条码实例


 最近我项目需要生成条码,那我就找了一下相关资料发现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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM