『Code 39条形码介绍』
usingSystem.Drawing;
usingSystem.Drawing.Imaging;
publicabstractclassDrawImageBord

...{
protectedvirtualstringBordRuleName

...{

get...{returnstring.Empty;}
}

protectedvirtualSystem.Collections.HashtableRoles

...{

get...{returnnewSystem.Collections.Hashtable();}
}

stringdrawString;
intwidth=800;//画布的宽度(可计算)
intheight=36;//1CM
intunitWidth=1;//

intcurrentLocation=0;

publicDrawImageBord(strings)

...{
drawString=s;
}

publicvirtualvoidDraw(System.IO.Streamtarget)

...{
Bitmapbm=newBitmap(width,height);
Graphicsg=Graphics.FromImage(bm);
g.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.Default;
g.TextRenderingHint=System.Drawing.Text.TextRenderingHint.AntiAlias;

//画布和边的设定
g.Clear(Color.White);

g.DrawRectangle(Pens.White,0,0,width,height);
for(inti=0;i<drawString.Length;i++)

...{
this.DrawString(drawString[i].ToString(),g);
}
bm.Save(target,ImageFormat.Jpeg);
}
protectedvirtualvoidDrawString(strings,Graphicsg)

...{
System.Collections.Hashtablehash=this.Roles;
objecto=hash[s];
if(o==null)return;
char[]chars=o.ToString().ToCharArray();
if(chars.Length>9)return;
SolidBrushblackBrush=newSolidBrush(Color.Black);
SolidBrushwiteBrush=newSolidBrush(Color.White);

for(inti=0;i<5;i++)

...{
//画第一个0黑条
if(chars[i]=='0')

...{
Rectanglere1=newRectangle(currentLocation,0,unitWidth,height);
g.FillRectangle(blackBrush,re1);
currentLocation+=unitWidth;
}
else

...{
Rectanglere1=newRectangle(currentLocation,0,3*unitWidth,height);
g.FillRectangle(blackBrush,re1);
currentLocation+=3*unitWidth;
}
//画第6个5白条
if((i+5)<9)

...{
if(chars[i+5]=='0')

...{
Rectanglere1=newRectangle(currentLocation,0,unitWidth,height);
g.FillRectangle(witeBrush,re1);
currentLocation+=unitWidth;
}
else

...{
Rectanglere1=newRectangle(currentLocation,0,3*unitWidth,height);
g.FillRectangle(witeBrush,re1);
currentLocation+=3*unitWidth;
}
}
}
Rectanglere2=newRectangle(currentLocation,0,unitWidth,height);
g.FillRectangle(witeBrush,re2);
currentLocation+=unitWidth;

}
}
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;


/**//**//**////<summary>
///CODE39DrawImageBord的摘要说明
///</summary>
publicclassCODE39DrawImageBord:DrawImageBord

......{
privateSystem.Collections.Hashtablehash=newSystem.Collections.Hashtable();
protectedoverridestringBordRuleName

......{

get......{return"CODE39";}
}
publicCODE39DrawImageBord(strings)
:base(s)

......{

}

protectedoverrideSystem.Collections.HashtableRoles

......{
get

......{
if(hash.Count>0)returnhash;
hash.Add("0","001100100");
hash.Add("1","100010100");
hash.Add("2","010010100");
hash.Add("3","110000100");
hash.Add("4","001010100");
hash.Add("5","101000100");
hash.Add("6","011000100");
hash.Add("7","000110100");

hash.Add("8","100100100");
hash.Add("9","010100100");
hash.Add("A","100010010");
hash.Add("B","010010010");
hash.Add("C","110000010");
hash.Add("D","001010010");
hash.Add("E","101000010");

hash.Add("F","011000010");
hash.Add("G","000110010");
hash.Add("H","100100010");
hash.Add("I","010100010");
hash.Add("J","001100010");
hash.Add("K","100010001");
hash.Add("L","010010001");

hash.Add("M","110000001");
hash.Add("N","001010001");
hash.Add("O","101000001");
hash.Add("P","011000001");
hash.Add("Q","000110001");
hash.Add("R","100100001");
hash.Add("S","010100001");


hash.Add("T","001100001");
hash.Add("U","100011000");
hash.Add("V","010011000");
hash.Add("W","110001000");
hash.Add("X","001011000");
hash.Add("Y","101001000");
hash.Add("Z","011001000");


hash.Add("-","000111000");
hash.Add("%","100101000");
hash.Add("$","010101000");
hash.Add("*","001101000");

returnhash;
}
}
}
protectedvoidPage_Load(objectsender,EventArgse)

...{
CODE39DrawImageBorddr=newCODE39DrawImageBord("*3949178*");
dr.Draw(Response.OutputStream);

}
code39条码能表示字母、数字和其它一些符号共43个字符:A -Z, 0-9, -.$/ + %, space等,其主要特点如下:
◆条码的长度是可变化的
◆通常用“*”号作为起始、终止符
◆校验码不用
◆代码密度介于3 - 9.4个字符/每英寸
◆空白区是窄条的10倍
◆用于工业、图书、以及票证自动化管理上
◆条码的长度是可变化的
◆通常用“*”号作为起始、终止符
◆校验码不用
◆代码密度介于3 - 9.4个字符/每英寸
◆空白区是窄条的10倍
◆用于工业、图书、以及票证自动化管理上
三九码是Intermec公司于1975年推出的一种条码,它可表示数字、英文字母以及“-”、“.”、“/”、“ ”、“%”、“$”、“ ”(空格)和“*”共44个符号,其中“*”仅作为启始符和终止符。
三九码且有编码规则简单、误码率低、所能表示字符个数多等特点,因此在各个领域有着极为广泛的应用。我国也制定了相应的国家标准(GB12908-91)。
三九码仅有两种单元宽度——分别为宽单元和窄单元。宽单元这宽度为窄单元的1到3倍,一般多选用2倍、2.5倍或3倍。三九码的每一个条码字符由九个单元组成,其中有三个宽单元,其余是窄单元,因此称为三九码。
我国有的图书馆使用的39码使用了特殊的校验字符,条码软件都可打印适用于图书馆的39码。
三九码且有编码规则简单、误码率低、所能表示字符个数多等特点,因此在各个领域有着极为广泛的应用。我国也制定了相应的国家标准(GB12908-91)。
三九码仅有两种单元宽度——分别为宽单元和窄单元。宽单元这宽度为窄单元的1到3倍,一般多选用2倍、2.5倍或3倍。三九码的每一个条码字符由九个单元组成,其中有三个宽单元,其余是窄单元,因此称为三九码。
我国有的图书馆使用的39码使用了特殊的校验字符,条码软件都可打印适用于图书馆的39码。
代码原创: LovlyPuppy
实现该功能分两个类,第一个类 DrawImageBord.cs










































































































第二个类CODE39DrawImageBord.cs 继承DrawImageBord.cs



























































































调用的方法:







--显示结果:

补充说明:
生成的这个条码,并没有用扫描枪去识别,
以后我会用Symbol DS6608数字扫描器 来识别它的准确性.
以后我会用Symbol DS6608数字扫描器 来识别它的准确性.