ASP adodb.stream 取 Win32 .bmp 图片完整文件头信息 By shawl.qiu

ASP adodb.stream 取 Win32 .bmp 图片完整文件头信息 By shawl.qiu


摘要:
N久前,我就想用 ASP 取得图片的宽高信息, 但发现这不是一件简单的事情, 非常非常复杂...
因为当时没有需求需要去弄这些, 就不了了之...
这阵子需要完整掌握这个技术, so.......就下决心搞了..

现在已经把 .bmp 这个格式完整完美的搞定喽, 接下来会把 .gif, .jpg, .jpeg, .png, .swf 这些格式完完整整的掌握, 不掌握不行呀...

本文作用:
演示了用ASP 的内置组件 adodb.stream 取得 .bmp 的完整文件头信息, 包括文件大小, 宽度, 高度等.

应用到的技术:
一个转二进制字节为数值的函数
一个转二进制字节为字符串的函数
内置组件 adodb.stream

目录:
1. 主内容: 完整例子
2. 参考文献
3. 预览

shawl.qiu
2006-09-16
http://blog.csdn.net/btbtd

1. 主内容: 完整例子
  1. linenum
  2. <%
  3.     dim file:file=server.MapPath("a.bmp")
  4.     dim temp
  5.     dim stm
  6.     set stm=createObject("adodb.stream")
  7.         with stm
  8.             .type = 1
  9.             .open
  10.             .loadFromFile file
  11.             temp=.read
  12.             .close
  13.         end with    
  14.     set stm=nothing
  15.         response.write "bmp file info ("&file&"):<br/>"
  16.         response.write "<br/>#1-2 signature, must be BM: "&binToStr(midB(temp,1,2))
  17.         response.write "<br/>#3-6 size of BMP file in bytes (unreliable): "&binToNum(midB(temp,3,4))
  18.         response.write "<br/>#7-10 reserved, must be zero: "&binToNum(midB(temp,7,4))
  19.         response.write "<br/>#11-14 offset to start of image data in bytes : "&binToNum(midB(temp,11,4))
  20.         response.write "<br/>#15-18 size of BITMAPINFOHEADER structure, must be 40 : "&binToNum(midB(temp,15,4))
  21.         response.write "<br/>#19-22 image width in pixels : "&binToNum(midB(temp,19,4))
  22.         response.write "<br/>#23-26 image height in pixels : "&binToNum(midB(temp,23,4))
  23.         response.write "<br/>#27-28 number of planes in the image, must be 1 : "&binToNum(midB(temp,27,1))
  24.         response.write "<br/>#29-30 number of bits per pixel (1, 4, 8, or 24) : "&binToNum(midB(temp,29,1))
  25.         response.write "<br/>#31-34 compression type (0=none, 1=RLE-8, 2=RLE-4) : "&binToNum(midB(temp,31,4))
  26.         response.write "<br/>#35-38 size of image data in bytes (including padding) : "&binToNum(midB(temp,35,4))
  27.         response.write "<br/>#39-42 horizontal resolution in pixels per meter (unreliable) : "&binToNum(midB(temp,39,4))
  28.         response.write "<br/>#43-46 vertical resolution in pixels per meter (unreliable) : "&binToNum(midB(temp,43,4))
  29.         response.write "<br/>#47-50 number of colors in image, or zero : "&binToNum(midB(temp,47,4))
  30.         response.write "<br/>#51-54 number of important colors, or zero : "&binToNum(midB(temp,51,4))
  31.     private function binToNum(bin)
  32.     '二进制转为 Numeric
  33.         dim i:binToNum=0
  34.         for i=lenB(bin) to 1 step -1
  35.             binToNum=binToNum*256+ascB(midB(bin,i,1))
  36.         next 'shawl.qiu code'
  37.     end function
  38.     
  39.     private function binToStr(bin)
  40.     '二进制转为 string
  41.         dim i, iByt, sByt, bLen:bLen=lenB(bin)
  42.         for i=1 to bLen
  43.             sByt=midB(bin,i,1):iByt=ascB(sByt)
  44.             if iByt<128 then
  45.                 binToStr=binToStr&chr(iByt)
  46.             else:i=i+1
  47.                 if i<=bLen then binToStr=binToStr&chr(ascW(sByt&sByt))
  48.             end if
  49.         next 'shawl.qiu'
  50.     end function
  51. %>

2. 参考文献
https://secure.wikimedia.org/wikipedia/zh/wiki/BMP
http://www.fastgraph.com/help/bmp_header_format.html

3. 预览
bmp file info (G:/My Documents/Index_ASP_mssql/a.bmp):

#1-2 signature, must be BM: BM
#3-6 size of BMP file in bytes (unreliable): 589878
#7-10 reserved, must be zero: 0
#11-14 offset to start of image data in bytes : 54
#15-18 size of BITMAPINFOHEADER structure, must be 40 : 40
#19-22 image width in pixels : 512
#23-26 image height in pixels : 384
#27-28 number of planes in the image, must be 1 : 1
#29-30 number of bits per pixel (1, 4, 8, or 24) : 24
#31-34 compression type (0=none, 1=RLE-8, 2=RLE-4) : 0
#35-38 size of image data in bytes (including padding) : 589824
#39-42 horizontal resolution in pixels per meter (unreliable) : 0
#43-46 vertical resolution in pixels per meter (unreliable) : 0
#47-50 number of colors in image, or zero : 0
#51-54 number of important colors, or zero : 0
 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值