您的位置:首页 > 编程语言 > C#

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

2015-05-22 15:32 435 查看
//首先引用 条码库BarcodeLib.dll

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
{
}
}
}
}
  


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: