日期:2009-01-02  浏览次数:21054 次

示例图片:XBM图片是一个纯文本的文件,可以用ASP来自动生成。可以用它来使用网站登陆的验证码;
我们用记事本打开该文件进行分析:
其文件结构为:
#define counter_width 48
#define counter_height 9
static unsigned char counter_bits[]={7c,3c,7c,3c,70,3c,fe,7c,fe,7c,78,7c,ee,ee,ee,ee,7c,ee,e0,ee,60,ee,74,ee,70,fe,30,fe,

70,fe,38,ec,e0,ec,70,ec,1c,e0,ee,e0,70,e0,fe,7e,fe,7e,70,7e,fe,3c,7c,3c,70,3c}
文件扩展名为:.xbm

#define counter_width 48 '这儿定义的是图片的宽度,一般为8的倍数
#define counter_height 9 '这儿定义的是图片的高度,是任意的。
static unsigned char counter_bits[]={7c,3c,7c,3c,70,3c,fe,7c,fe,7c,78,7c,ee,ee,ee,ee,7c,ee,e0,ee,60,ee,74,ee,70,fe,30,fe,70,fe,38,ec,e0,ec,70,ec,1c,e0,ee,e0,

70,e0,fe,7e,fe,7e,70,7e,fe,3c,7c,3c,70,3c} '这儿是图片用来显示内容的十六进制的代码

正如static unsigned char英文意思为静态的,无符号的,烧焦的。它只能用来显示黑白两种颜色。二进制中的1将来用显示为黑色,0为白色。

下面为0~9数字的二进制数组(其中的图片样式仅试用于本例。如果需要别的0~9数字样式,请另自行生成)

'此处声明0~9绘图用数组

dim num(9,8)
'数字0
num(0,0)="0x38"
num(0,1)="0x7c"
num(0,2)="0xee"
num(0,3)="0xee"
num(0,4)="0xee"
num(0,5)="0xee"
num(0,6)="0xee"
num(0,7)="0x7c"
num(0,8)="0x38"
'数字1
num(1,0)="0x70"
num(1,1)="0x78"
num(1,2)="0x7c"
num(1,3)="0x74"
num(1,4)="0x70"
num(1,5)="0x70"
num(1,6)="0x70"
num(1,7)="0x70"
num(1,8)="0x70"
'数字2
num(2,0)="0x7c"
num(2,1)="0xfe"
num(2,2)="0xee"
num(2,3)="0xe0"
num(2,4)="0x70"
num(2,5)="0x38"
num(2,6)="0x1c"
num(2,7)="0xfe"
num(2,8)="0xfe"
'数字3
num(3,0)="0x7c"
num(3,1)="0xfe"
num(3,2)="0xee"
num(3,3)="0x60"
num(3,4)="0x30"
num(3,5)="0xe0"
num(3,6)="0xee"
num(3,7)="0xfe"
num(3,8)="0x7c"
'数字4
num(4,0)="0x70"
num(4,1)="0x78"
num(4,2)="0x7c"
num(4,3)="0x76"
num(4,4)="0x77"
num(4,5)="0xff"
num(4,6)="0xff"
num(4,7)="0x70"
num(4,8)="0x70"
'数字5
num(5,0)="0xfc"
num(5,1)="0xfc"
num(5,2)="0x0c"
num(5,3)="0x7e"
num(5,4)="0xfe"
num(5,5)="0xe0"
num(5,6)="0xee"
num(5,7)="0xfe"
num(5,8)="0x7c"
'数字6
num(6,0)="0x78"
num(6,1)="0xfc"
num(6,2)="0x0e"
num(6,3)="0x6e"
num(6,4)="0xfe"
num(6,5)="0xee"
num(6,6)="0xee"
num(6,7)="0xfc"
num(6,8)="0x78"
'数字7
num(7,0)="0xfe"
num(7,1)="0xfe"
num(7,2)="0x60"
num(7,3)="0x70"
num(7,4)="0x38"
num(7,5)="0x38"
num(7,6)="0x18"
num(7,7)="0x1c"
num(7,8)="0x1c"
'数字8
num(8,0)="0x7c"
num(8,1)="0xfe"
num(8,2)="0xee"
num(8,3)="0x7c"
num(8,4)="0x7c"
num(8,5)="0xee"
num(8,6)="0xee"
num(8,7)="0xfe "
num(8,8)="0x7c"
'数字9
num(9,0)="0x3c"
num(9,1)="0x7c"
num(9,2)="0xee"
num(9,3)="0xee"
num(9,4)="0xfe"
num(9,5)="0xec"
num(9,6)="0xe0"
num(9,7)="0x7e"
num(9,8)="0x3c"


下面实现这个的代码,把上面的数字数组(红色的)保存为funNum.ASP
下面的文件部分,单独保存为一个ASP页<%
const countHeight=9 '图片的高度
const countlength=6 '图片里数字的位数
const numBinBit=8 '这是数字数组里的二进制位数,好象只能使用八位以下的即11111111
const countWidth=48 'countlength*numBinBit得到
const imgtype="image/x-xbitmap"
dim countBody '图片信息
dim tmpcountbody '用于存放后面生成的图片数据
tmpcountbody=""
countBody="#define js_counter_width " & countWidth & vbCrLf
countBody=countBody & "#define js_counter_height " & countHeight & vbCrLf
countBody=countBody & "static unsigned char js_counter_bits[]={" & vbCrLf
dim numid '需要生成图片的数字
dim numarray() '将取得的numid分割成一个个的数字组成一维数组
numid="369245" '编写一个函数用来生成数字即可
if len(numid)for i=1 to countLength-len(numid)
numid="0" & numid
next
end if
redim numarray(len(numid)-1) '直接定义数组时要指字一整型数值,重定义数组大小时可使用表达式
for i=0 to ubound(numarray,1)
numarray(i)=mid(numid,i+1,1)
next
for i=0 to countHeight-1
for j=0 to countlength-1
tmpcountbody=tmpcountbody & num(numarray(j),i) & ","
next
next
tmpcountbody=left(tmpcountbody,len(tmpcountbody)-1)
countBody=countBody & tmpcountbody & "}"
response.contenttype=imgtype
response.write countBody
%>