站长之站 站长之站QQ群:16356000 100345456 16263640 130690866
还没有任何记录...
当前位置:站长之站 > 编程开发 > 正文 > 用asp生成bmp图片

用asp生成bmp图片

来源:网络作者:网络日期:2020/9/14 2:13:00收藏
本文链接:用asp生成bmp图片http://www.cncncc.com/ArtLang/Show.Asp?id=1979

bmp图片规则:bmp文件有54个字节的文件头,其中包括了bmp文件标志“bm”,文件大小,位图文件起始位置,长,宽,位图位数1/4/8/24(1,8个像素占1个字节;4,2个像素占1个字节;8,1个像素占1个字节;24,1个像素占3个字节;)等信息。不过最简单的方法是先用画图板做一个相同大小的空图片,把头信息记录下来。
bmp文件实际显示部分,是从左下角开始,到右上角结束,详细记录了文件的每个像素,如果用24位位图表示的话,用3个字节表示rgb。红色表示就是 ff 00 ff,黑色就是00 00 00,白色是ff ff ff...
如果我们要表示一个数字或字母,我们可以用一个10x10的距阵来表示,比如1用下面的距阵表示:
1111011111
1100011111
1111011111
1111011111
1111011111
1111011111
1111011111
1111011111
1111011111
1100000111
当然也可以用一个更大的距阵来表示一个更丰富的样式。
明白了原理,接下来就好用程序实现了,我们用response.binarywrite方法写入文件头,再用程序写入文件体。
下面是一个用程序生成浏览者ip地址的程序:
<%
response.expires = -9999
response.addheader "cache-control","no-cache"
response.contenttype = "image/bmp"
const ccode = "0123456789. " '数据值

dim vcolor(2)
vcolor(0) = chrb(0) & chrb(0) & chrb(0) '黑
vcolor(1) = chrb(255) & chrb(255) & chrb(255) '白

ip=request.servervariables("http_x_forwarded_for") '得到ip值
if ip="" then
ip=request.servervariables("remote_addr")
end if

ls=split(ip,".",-1,1) '劈开ip
for j=0 to 3 '处理分组
if len(ls(j))<3 then '如果长度少于3
  spac=""
  for k=1 to 3-len(ls(j)) '加3-len个空格
   spac=spac+" "
  next
  ls(j)=spac+ls(j) '转换长度足够的ls(j)
end if
next

str="" '二次处理ip串,over
for k=0 to 3
str=str+ls(k)+"."
next
str=left(str,15)

dim vcode(15) '三次处理成数组
for x = 0 to 14
vcode(x) = mid(str,x+1,1) '等于什么值?
vcode(x)=instr(1,ccode,vcode(x),1)-1 '值在串中是第几?
'response.write vcode(x)&"<br>"
next

dim vnumber(12)
vnumber(0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
vnumber(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
vnumber(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
vnumber(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
vnumber(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
vnumber(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
vnumber(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
vnumber(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
vnumber(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
vnumber(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
vnumber(10) ="1111111111111111111111111111111111111111111111111111111111111111111111111111111111110011111111001111"
vnumber(11) ="1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"

response.binarywrite chrb(66)&chrb(77)&chrb(222)&chrb(17)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(54)&_
chrb(0)&chrb(0)&chrb(0)&chrb(40)&chrb(0)&chrb(0)&chrb(0)&chrb(150)&chrb(0)&chrb(0)&chrb(0)&chrb(10)&chrb(0)&chrb(0)&_
chrb(0)&chrb(1)&chrb(0)&chrb(24)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(168)&chrb(17)

response.binarywrite chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&_
chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)
dim x,y,z
for x = 9 to 0 step -1 '逐行
for y = 0 to 14 '逐字
for z = 1 to 10 '逐像素的r/g/b,因为vcolor()已经定义每个rgb值了,如果是8位位图,使用一个字节即可
   response.binarywrite vcolor(mid(vnumber(vcode(y)), x * 10 + z , 1)) '写入流
next
next
response.binarywrite vcolor(1) '为每一行的增加一个行尾标志
next
%>

当然,这个程序生成的流和位图定义有点不太符合,图片有点斜,大家慢慢研究吧...
下面是我修改的网上的生成彩色随机验证码的程序, 附件一直提示file1格式不对, 只好粘在下面
<%
response.contenttype = "image/bmp"
call com_creatvalidcode()
sub com_creatvalidcode()
randomize
dim i, ii, iii
const camount = 36 '数值个数
const ccode = "0123456789abcdefghijklmnopqrstuvwxyz" '数值范围

dim vcolordata(2)
vcolordata(0) = "" '黑色点要转为彩色点,暂时不定义
vcolordata(1) = chrb(255) & chrb(255) & chrb(255) '白点

<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">dim vcode(4), vcodes '产生一组任意数
for i = 0 to 3
vcode(i) = int(rnd * camount) '数组等于总数*随机数
vcodes=vcodes&mid(ccode,vcode(i)+1,1) '串等于串加上后续值
next
session("checkcode")=vcodes '记录产生的串值<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">dim vnumberdata(36)
vnumberdata(0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
vnumberdata(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
vnumberdata(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
vnumberdata(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
vnumberdata(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
vnumberdata(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
vnumberdata(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
vnumberdata(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
vnumberdata(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
vnumberdata(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
vnumberdata(10) = "1111011111111101111111101011111110101111111010111111101011111100000111110111011111011101111000100011"
vnumberdata(11) = "1000000111110111101111011110111101110111110000111111011101111101111011110111101111011110111000000111"
vnumberdata(12) = "1110000011110111101110111110111011111111101111111110111111111011111111101111101111011101111110001111"
vnumberdata(13) = "1000001111110111011111011110111101111011110111101111011110111101111011110111101111011101111000001111"
vnumberdata(14) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011110111000000111"
vnumberdata(15) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011111111000111111"
vnumberdata(16) = "1110000111110111011110111101111011111111101111111110111111111011100011101111011111011101111110001111"
vnumberdata(17) = "1000100011110111011111011101111101110111110000011111011101111101110111110111011111011101111000100011"
vnumberdata(18) = "1100000111111101111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
vnumberdata(19) = "1110000011111110111111111011111111101111111110111111111011111111101111111110111110111011111000011111"
vnumberdata(20) = "1000100011110111011111011011111101011111110001111111010111111101101111110110111111011101111000100011"
vnumberdata(21) = "1000111111110111111111011111111101111111110111111111011111111101111111110111111111011110111000000011"
vnumberdata(22) = "1000100011110010011111001001111100100111110101011111010101111101010111110101011111010101111001010011"
vnumberdata(23) = "1000100011110011011111001101111101010111110101011111010101111101100111110110011111011001111000110111"
vnumberdata(24) = "1110001111110111011110111110111011111011101111101110111110111011111011101111101111011101111110001111"
vnumberdata(25) = "1000000111110111101111011110111101111011110000011111011111111101111111110111111111011111111000111111"
vnumberdata(26) = "1110001111110111011110111110111011111011101111101110111110111011111011101001101111011001111110001011"
vnumberdata(27) = "1000001111110111011111011101111101110111110000111111010111111101101111110110111111011101111000110011"
vnumberdata(28) = "1110000011110111101111011110111101111111111001111111111001111111111011110111101111011110111100000111"
vnumberdata(29) = "1000000011101101101111110111111111011111111101111111110111111111011111111101111111110111111110001111"
vnumberdata(30) = "1000100011110111011111011101111101110111110111011111011101111101110111110111011111011101111110001111"
vnumberdata(31) = "1000100011110111011111011101111101110111111010111111101011111110101111111010111111110111111111011111"
vnumberdata(32) = "1001010011110101011111010101111101010111110101011111001001111110101111111010111111101011111110101111"
vnumberdata(33) = "1000100011110111011111101011111110101111111101111111110111111110101111111010111111011101111000100011"
vnumberdata(34) = "1000100011110111011111011101111110101111111010111111110111111111011111111101111111110111111110001111"
vnumberdata(35) = "1100000011110111011111111101111111101111111110111111110111111111011111111011111111101110111100000011"<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">response.binarywrite chrb(66) & chrb(77) & chrb(230) & chrb(4) & chrb(0) & chrb(0) & chrb(0) & chrb(0) &_
chrb(0) & chrb(0) & chrb(54) & chrb(0) & chrb(0) & chrb(0) & chrb(40) & chrb(0) &_
chrb(0) & chrb(0) & chrb(40) & chrb(0) & chrb(0) & chrb(0) & chrb(10) & chrb(0) &_
chrb(0) & chrb(0) & chrb(1) & chrb(0)<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">response.binarywrite chrb(24) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(176) & chrb(4) &_
chrb(0) & chrb(0) & chrb(18) & chrb(11) & chrb(0) & chrb(0) & chrb(18) & chrb(11) &_
chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) &_
chrb(0) & chrb(0)
for i = 9 to 0 step -1 '行
for ii = 0 to 3 '字数
for iii = 1 to 10 '像素点
  if mid(vnumberdata(vcode(ii)), i * 10 + iii , 1) ="0" then '产生彩色点,减去一个固定值,可使颜色偏深
   dim a,b,c
   a=abs(rnd * 256-60)
   b=abs(rnd * 256-128)
   c=abs(rnd * 256-60)
   vcolordata(0) = chrb(a) & chrb(b) & chrb(c)
   response.binarywrite vcolordata(mid(vnumberdata(vcode(ii)), i * 10 + iii , 1))
  else
   dim d,e,f '产生彩色背景,颜色偏浅,也可以随机生成噪点做背景
   d=abs(rnd * 255)
   e=abs(rnd * 255)
   f=abs(rnd * 255)
   if d+e+f>580 then
   vcolordata(1) = chrb(d) & chrb(e) & chrb(f)
   response.binarywrite vcolordata(mid(vnumberdata(vcode(ii)), i * 10 + iii , 1))
   else
   response.binarywrite vcolordata(mid(vnumberdata(vcode(ii)), i * 10 + iii , 1))
   end if
  end if
next
next
next
end sub
%><p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">
------------------------------------------------------------------------------<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">另做的一个小ip图片
--------------------------------------------------------------------------------
黑白8位位图图片,非常正规,图片非常小:262个字节
注:8位黑白位图,指8个像素占一个字节,第一个点是黑色,另七个点是白色的话,字节值是80;第二点是黑色,其它点是白色,字节值是40,以此类推...多个点是黑色加在一起,8个像素全是黑色,字节值是ff...
<%
response.expires = -9999
response.addheader "cache-control","no-cache"
response.contenttype = "image/bmp"
const ccode = "0123456789. " '数据值<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">dim vcolor(2)
vcolor(0) = chrb(0) '黑
vcolor(1) = chrb(80) '白<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">ip=request.servervariables("http_x_forwarded_for") '得到ip值
if ip="" then
ip=request.servervariables("remote_addr")
end if<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">ls=split(ip,".",-1,1) '劈开ip
for j=0 to 3 '处理分组
if len(ls(j))<3 then '如果长度少于3
  spac=""
  for k=1 to 3-len(ls(j)) '加3-len个空格
   spac=spac+" "
  next
  ls(j)=spac+ls(j) '转换长度足够的ls(j)
end if
next<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">str="" '二次处理ip串
for k=0 to 3
str=str+ls(k)+"."
next
str=left(str,15)<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">dim vnumber(12)
vnumber(0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
vnumber(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
vnumber(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
vnumber(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
vnumber(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
vnumber(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
vnumber(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
vnumber(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
vnumber(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
vnumber(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
vnumber(10) ="1111111111111111111111111111111111111111111111111111111111111111111111111111111111110011111111001111"
vnumber(11) ="1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">dim x,y,vcode(15) '三次处理成数组
for x = 0 to 14
vcode(x) = mid(str,x+1,1) '等于什么值?
vcode(x)=instr(1,ccode,vcode(x),1)-1 '值在串中是第几?
next<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">response.binarywrite chrb(66)&chrb(77)&chrb(8)&chrb(1)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(62)&_
chrb(0)&chrb(0)&chrb(0)&chrb(40)&chrb(0)&chrb(0)&chrb(0)&chrb(150)&chrb(0)&chrb(0)&chrb(0)&chrb(10)&chrb(0)&chrb(0)&_
chrb(0)&chrb(1)&chrb(0)&chrb(1)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(202)
response.binarywrite chrb(0)&chrb(0)&chrb(0)&chrb(18)&chrb(11)&chrb(0)&chrb(0)&chrb(18)&chrb(11)&chrb(0)&chrb(0)&_
chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(0)&chrb(255)&chrb(255)&chrb(255)&chrb(0)&chrb(0)&_
chrb(0)&chrb(0)&chrb(0)<p style="margin-top: 0px; padding: 0px; border: 0px; list-style: none; overflow-wrap: normal; word-break: normal; line-height: 18px; color: rgb(255, 201, 187); font-family: verdana, 宋体, sans-serif; font-size: 12px; white-space: normal; background-color: rgb(209, 59, 61);">dim points(10)
for x=9 to 0 step -1 '处理成10行150列的像素串
points(x)=""
for y=0 to 14
 points(x)=points(x)&mid(vnumber(vcode(y)),x*10+1,10)
next
for z=0 to 18 '劈开像素串,分别处理
  lsstr=mid(points(x),z*8+1,8)
  byteval=0
  if mid(lsstr,1,1)="0" then byteval=byteval+128
  if mid(lsstr,2,1)="0" then byteval=byteval+64
  if mid(lsstr,3,1)="0" then byteval=byteval+32
  if mid(lsstr,4,1)="0" then byteval=byteval+16
  if mid(lsstr,5,1)="0" then byteval=byteval+8
  if mid(lsstr,6,1)="0" then byteval=byteval+4
  if mid(lsstr,7,1)="0" then byteval=byteval+2
  if mid(lsstr,8,1)="0" then byteval=byteval+1
  response.binarywrite chrb(byteval)
next
response.binarywrite vcolor(0) '写行尾标志
next
response.binarywrite vcolor(0) '写图尾标志
%>



作者:站长之站 收集整理,任何媒体转发须保留作者个人微信和来源,不尊重作者劳动的行为将受到举报。
本文链接:用asp生成bmp图片http://www.cncncc.com/ArtLang/Show.Asp?id=1979

【用asp生成bmp图片】由站长之站收集整理,您可以自由传播,请主动带上本文链接

觉得有用就多来支持一下,没有能帮到您,站长之站也只能表示遗憾,希望有一天能帮到您。

(责任编辑:站长之站)

上一篇:js中的反斜杠 (\)是什么意思-作用

下一篇:没有数据

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
站长之站 · CNCMS
站长之站
编程开发
ASP教程 .NET教程 JSP教程 PHP教程 Xml/Xslt Shtml教程 CGI专区 JavaScrip 其他编程
服务器类
Web服务器 Ftp服务器 Mail服务器 Dns服务器 Linux服务器 Win服务器 安全防护 服务器其他
网页设计
Html教程 设计心得 动态网页 JS/Ajax Div/Css CSS教程 设计其它
软件教程
Photoshop Fireworks FLASH Dreamweaver Frontpage 其他教程
数据库类
MSAccess MS_SQL My_SQL VFP PowerBuilder Oracle 其它数据
全站导航
编程开发服务器类网页设计软件教程数据库类
关于我们/版权
版权所有:
Copyright © 2008 - 2020 站长之站 www.cncncc.com
PowerBy:CNCMS(5.1.20)

苏ICP备16002106号-1