码迷,mamicode.com
首页 > Windows程序 > 详细

C# 生成条形码图片,效果不错

时间:2015-05-22 16:33:16      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BarcodeLib;
using System.IO;


namespace Tool.Gui
{
  public  class clsLisBarCode
    {

        Barcode m_BarCoe = new Barcode();
        string m_strPath;
        public clsLisBarCode()
        {
            m_strPath = System.Windows.Forms.Application.StartupPath + @"\Temp";
        }
///p_strBMPFile 文件路径
        public void CreateCodeBMP(string p_strCode, out string p_strBMPFile)
        {
            CreateCodeBMP(p_strCode, out p_strBMPFile, "");
        }
///p_strBMPFile 文件路径
        public void CreateCodeBMP(string p_strCode, out string p_strBMPFile, string p_strType)
        {
            if (!Directory.Exists(m_strPath))
            {
                Directory.CreateDirectory(m_strPath);
            }
            try
            {
                foreach (string file in Directory.GetFiles(m_strPath))
                {
                    File.Delete(file);
                }
            }
            catch { }
            p_strBMPFile = "";
            TYPE type = TYPE.UNSPECIFIED;
            switch (p_strType)
            {
                case "UPCA": type = TYPE.UPCA; break;
                case "UPC-A (Numbered)": type = TYPE.UPCA; break;
                case "UPC-E": type = TYPE.UPCE; break;
                case "UPC 2 Digit Ext.": type = TYPE.UPC_SUPPLEMENTAL_2DIGIT; break;
                case "UPC 5 Digit Ext.": type = TYPE.UPC_SUPPLEMENTAL_5DIGIT; break;
                case "EAN13": type = TYPE.EAN13; break;
                case "JAN13": type = TYPE.JAN13; break;
                case "EAN8": type = TYPE.EAN8; break;
                case "ITF14": type = TYPE.ITF14; break;
                case "Codabar": type = TYPE.Codabar; break;
                case "PostNet": type = TYPE.PostNet; break;
                case "Bookland/ISBN": type = TYPE.BOOKLAND; break;
                case "Code11": type = TYPE.CODE11; break;
                case "Code39": type = TYPE.CODE39; break;
                case "Code39 Extended": type = TYPE.CODE39Extended; break;
                case "Code93": type = TYPE.CODE93; break;
                case "LOGMARS": type = TYPE.LOGMARS; break;
                case "MSI": type = TYPE.MSI_Mod10; break;
                case "Interleaved 2 of 5": type = TYPE.Interleaved2of5; break;
                case "Standard 2 of 5": type = TYPE.Standard2of5; break;
                case "Code128": type = TYPE.CODE128; break;
                case "Code128A": type = TYPE.CODE128A; break;
                case "Code128B": type = TYPE.CODE128B; break;
                case "Code128C": type = TYPE.CODE128C; break;
                default: type = TYPE.CODE128; break;//,默认格式
            }
            try
            {
                if (type != TYPE.UNSPECIFIED)
                {
                    p_strBMPFile = m_strPath + @"\" + p_strCode + ".Bmp";
                    m_BarCoe.IncludeLabel = false;
                    m_BarCoe.Encode(type, p_strCode, 359, 150);//宽度 高度
                    m_BarCoe.SaveImage(p_strBMPFile, BarcodeLib.SaveTypes.BMP);
                }
            }
            catch
            {
            }
        }
    }
}
  

  

C# 生成条形码图片,效果不错

标签:

原文地址:http://www.cnblogs.com/china-guoch/p/4520292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!