<script type="text/javascript"><!--
document.body.oncopy = function() {
if (window.clipboardData) {
setTimeout(function() {
var text = clipboardData.getData("text");
if (text && text.length>300) {
text = text + "/r/n/n本文来自CSDN博客,转载请标明出处:" + location.href;
clipboardData.setData("text", text);
}
}, 100);
}
}
// --></script><script class="blogstory"><!--
function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}
// --></script>
EAN商品条码的类
这个使用的比较多
其实 前面的编码是根据前面的6来判断的。是类型A还是类型B
效果
使用方法
-
-
char
_ISBN=MyImage.BandCode.EAN13.EAN13ISBN(
"690102803695"
);
-
MessageBox.Show(_ISBN.ToString());
-
MyImage.BandCode.EAN13_EAN13Code=
new
MyImage.BandCode.EAN13();
-
_EAN13Code.Magnify=1;
-
_EAN13Code.Heigth=100;
-
_EAN13Code.FontSize=16;
-
pictureBox1.Image=_EAN13Code.GetCodeImage(
"6901028036955"
);
-
pictureBox1.Image.Save(@
"C:/1.bmp"
);
具体绘制类
-
using
System;
-
using
System.Collections;
-
using
System.ComponentModel;
-
using
System.Drawing;
-
using
System.Data;
-
namespace
MyImage.BandCode
-
{
-
public
class
EAN13
-
{
-
private
DataTablem_EAN13=
new
DataTable();
-
public
EAN13()
-
{
-
m_EAN13.Columns.Add(
"ID"
);
-
m_EAN13.Columns.Add(
"Type"
);
-
m_EAN13.Columns.Add(
"A"
);
-
m_EAN13.Columns.Add(
"B"
);
-
m_EAN13.Columns.Add(
"C"
);
-
m_EAN13.Rows.Add(
"0"
,
"AAAAAA"
,
"0001101"
,
"0100111"
,
"1110010"
);
-
m_EAN13.Rows.Add(
"1"
,
"AABABB"
,
"0011001"
,
"0110011"
,
"1100110"
);
-
m_EAN13.Rows.Add(
"2"
,
"AABBAB"
,
"0010011"
,
"0011011"
,
"1101100"
);
-
m_EAN13.Rows.Add(
"3"
,
"AABBBA"
,
"0111101"
,
"0100001"
,
"1000010"
);
-
m_EAN13.Rows.Add(
"4"
,
"ABAABB"
,
"0100011"
,
"0011101"
,
"1011100"
);
-
m_EAN13.Rows.Add(
"5"
,
"ABBAAB"
,
"0110001"
,
"0111001"
,
"1001110"
);
-
m_EAN13.Rows.Add(
"6"
,
"ABBBAA"
,
"0101111"
,
"0000101"
,
"1010000"
);
-
m_EAN13.Rows.Add(
"7"
,
"ABABAB"
,
"0111011"
,
"0010001"
,
"1000100"
);
-
m_EAN13.Rows.Add(
"8"
,
"ABABBA"
,
"0110111"
,
"0001001"
,
"1001000"
);
-
m_EAN13.Rows.Add(
"9"
,
"ABBABA"
,
"0001011"
,
"0010111"
,
"1110100"
);
-
}
-
private
uint
m_Height=40;
-
-
-
-
public
uint
Heigth{
get
{
return
m_Height;}
set
{m_Height=value;}}
-
private
byte
m_FontSize=0;
-
-
-
-
public
byte
FontSize{
get
{
return
m_FontSize;}
set
{m_FontSize=value;}}
-
-
private
byte
m_Magnify=0;
-
-
-
-
public
byte
Magnify{
get
{
return
m_Magnify;}
set
{m_Magnify=value;}}
-
public
BitmapGetCodeImage(
string
p_Text)
-
{
-
if
(p_Text.Length!=13)
throw
new
Exception(
"数字不是13位!"
);
-
string
_CodeText=p_Text.Remove(0,1);
-
string
_CodeIndex=
"101"
;
-
char
[]_LeftType=GetValue(p_Text.Substring(0,1),
"Type"
).ToCharArray();
-
for
(
int
i=0;i!=6;i++)
-
{
-
_CodeIndex+=GetValue(_CodeText.Substring(0,1),_LeftType[i].ToString());
-
_CodeText=_CodeText.Remove(0,1);
-
}
-
-
_CodeIndex+=
"01010"
;
-
-
for
(
int
i=0;i!=6;i++)
-
{
-
_CodeIndex+=GetValue(_CodeText.Substring(0,1),
"C"
);
-
_CodeText=_CodeText.Remove(0,1);
-
}
-
_CodeIndex+=
"101"
;
-
return
GetImage(_CodeIndex,p_Text);
-
}
-
-
-
-
-
-
-
private
string
GetValue(
string
p_Value,
string
p_Type)
-
{
-
if
(m_EAN13==
null
)
return
""
;
-
DataRow[]_Row=m_EAN13.Select(
"ID='"
+p_Value+
"'"
);
-
if
(_Row.Length!=1)
throw
new
Exception(
"错误的编码"
+p_Value.ToString());
-
return
_Row[0][p_Type].ToString();
-
}
-
-
-
-
-
-
private
BitmapGetImage(
string
p_Text,
string
p_ViewText)
-
{
-
char
[]_Value=p_Text.ToCharArray();
-
int
_FontWidth=0;
-
Font_MyFont=
null
;
-
if
(m_FontSize!=0)
-
{
-
#region获取符合大小的字体
-
_MyFont=
new
Font(
"宋体"
,m_FontSize);
-
Bitmap_MyFontBmp=
new
Bitmap(m_FontSize,m_FontSize);
-
Graphics_FontGraphics=Graphics.FromImage(_MyFontBmp);
-
-
for
(
byte
i=m_FontSize;i!=0;i--)
-
{
-
SizeF_DrawSize=_FontGraphics.MeasureString(p_ViewText.Substring(0,1),_MyFont);
-
if
(_DrawSize.Height>m_FontSize)
-
{
-
_MyFont=
new
Font(
"宋体"
,i);
-
}
-
else
-
{
-
_FontWidth=(
int
)_DrawSize.Width;
-
break
;
-
}
-
}
-
#endregion
-
}
-
if
(ScanDrawText(_MyFont,p_Text,_FontWidth)==
false
)
-
{
-
_FontWidth=0;
-
m_FontSize=0;
-
}
-
-
Bitmap_CodeImage=
new
Bitmap(_Value.Length*((
int
)m_Magnify+1)+(_FontWidth*2),(
int
)m_Height);
-
Graphics_Garphics=Graphics.FromImage(_CodeImage);
-
_Garphics.FillRectangle(Brushes.White,
new
Rectangle(0,0,_CodeImage.Width,_CodeImage.Height));
-
-
int
_Height=0;
-
int
_LenEx=_FontWidth;
-
for
(
int
i=0;i!=_Value.Length;i++)
-
{
-
int
_DrawWidth=m_Magnify+1;
-
if
(i==0||i==2||i==46||i==48||i==92||i==94)
-
{
-
_Height=(
int
)m_Height;
-
}
-
else
-
{
-
_Height=(
int
)m_Height-m_FontSize;
-
}
-
if
(_Value[i]==
'1'
)
-
{
-
_Garphics.FillRectangle(Brushes.Black,
new
Rectangle(_LenEx,0,_DrawWidth,_Height));
-
-
}
-
else
-
{
-
_Garphics.FillRectangle(Brushes.White,
new
Rectangle(_LenEx,0,_DrawWidth,_Height));
-
}
-
_LenEx+=_DrawWidth;
-
}
-
-
if
(_FontWidth!=0&&m_FontSize!=0)
-
{
-
int
_StarX=0;
-
int
_StarY=(
int
)m_Height-_MyFont.Height;
-
_Garphics.DrawString(p_ViewText.Substring(0,1),_MyFont,Brushes.Black,0,_StarY);
-
_StarX=_FontWidth+(3*(m_Magnify+1));
-
_Garphics.DrawString(p_ViewText.Substring(1,6),_MyFont,Brushes.Black,_StarX,_StarY);
-
_StarX=_FontWidth+(50*(m_Magnify+1));
-
_Garphics.DrawString(p_ViewText.Substring(7,6),_MyFont,Brushes.Black,_StarX,_StarY);
-
}
-
_Garphics.Dispose();
-
return
_CodeImage;
-
}
-
-
-
-
-
-
-
-
private
bool
ScanDrawText(Font_MyFont,
string
p_Text,
int
p_Width)
-
{
-
if
(_MyFont==
null
)
return
false
;
-
int
_Width=(p_Text.Length-6-5)*((
int
)m_Magnify+1);
-
if
((p_Width*12)>_Width)
return
false
;
-
return
true
;
-
}
-
-
-
-
-
-
public
static
char
EAN13ISBN(
string
_Numb)
-
{
-
int
_Sum=0;
-
int
_i=1;
-
foreach
(
char
_Char
in
_Numb)
-
{
-
if
(
"0123456789"
.IndexOf(_Char)<0)
continue
;
-
_Sum+=(_Char-
'0'
)*_i;
-
_i=_i==1?3:1;
-
}
-
return
"01234567890"
[10-_Sum%10];
-
}
-
-
}
-
}
剩下CODE39了 这个过几天再做把。
分享到:
相关推荐
NET 绘制 EAN13 (商品条码)sdasdas
能快速生成EAN13的条形码,用处很多,更多条形码知识,可以访问http://www.tz8.net
VB.NET条形码工具箱.zip 源码开放
VB.net绘制生成code128条形码的例子,另外还有EAN128、包括了Code128 A/B/C类型的条形码,程序非常好用,在文本框输入规定要求的数据,即时输入,即时生成。程序中为生成条形码,创建了一些函数,比如显示可见条码...
PB10.5通过EAN13条码字体实现EAN8和EAN13条码,直接使用EAN13条码字体是无法被识别的,需要将原始条码进行转换后,在通过该字体进行展示。
excel实现EAN-13条码的校验位(最后一位)的算法
EAN-13条形码生成的 C#源码
利用C语言生产条形码的代码,能够生成EAN13条形码,代码不够简洁,但功能完全,大约500多行
适用:按照需要生成EAN13标准的条形码
能够批量实现数据窗口内内容条形码的批量打印 ean8码为7位数值+1位校验位 ean13码为12位数值+1位校验位 code39码可为数值及字母的任意组合 三种条形码各有100个随机测试 按数据窗口字段内容编码,解决用控件不能实现...
Python 根据用户输入编码批量生成EAN-13条形码 Python源码Python 根据用户输入编码批量生成EAN-13条形码 Python源码Python 根据用户输入编码批量生成EAN-13条形码 Python源码Python 根据用户输入编码批量生成EAN-13...
基于C#的EAN-13条形码的算法及实现,不使用其他控件,完全由C#实现
1. 【左侧空白区】 2. 【前置码】 3. 【起始符】 4. 【左侧数据符】 5. 【国家代码】 6. 【中间分隔符】 7. 【右侧数据符】 8. 【校验符】
在Excel中利用字体文件生成Ean13条形码。内附代码VBA代码含效果展示。
【最新优化版】可根据输入的12位数字离线生成相应的EAN-13条形码,相较于Ver.1优化了初始界面,并且增加了两位输入数字(Ver.1只根据10位的输入数字,生成以69为固定开头的EAN-13条形码;Ver.2可自定义前置码以及第...
PB中利用字体实现EAN13条码的打印,不需要控件。请先将包里的ean13.ttf安装到Windows的字体Fonts目录下. 本方法可以很方便的将图书ISBN打印出条码。
matlab版EAN-13条形码识别系统,直接输入图片即可运行,有任何问题都可提出
TXT文档描述,。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
2:输入的长度为13位,输入不够的话会弹出提示,超出13位则无法输入 3:输入完成后可直接按“回车”或是单击“校验”按钮进行校验 4:采用 条码扫描仪 输入条码时会自动校验 5:完成一个校验后,单击“空格”后可...