-
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. 主内容: 完整例子
- linenum
- <%
- dim file:file=server.MapPath("a.bmp")
- dim temp
- dim stm
- set stm=createObject("adodb.stream")
- with stm
- .type = 1
- .open
- .loadFromFile file
- temp=.read
- .close
- end with
- set stm=nothing
- response.write "bmp file info ("&file&"):<br/>"
- response.write "<br/>#1-2 signature, must be BM: "&binToStr(midB(temp,1,2))
- response.write "<br/>#3-6 size of BMP file in bytes (unreliable): "&binToNum(midB(temp,3,4))
- response.write "<br/>#7-10 reserved, must be zero: "&binToNum(midB(temp,7,4))
- response.write "<br/>#11-14 offset to start of image data in bytes : "&binToNum(midB(temp,11,4))
- response.write "<br/>#15-18 size of BITMAPINFOHEADER structure, must be 40 : "&binToNum(midB(temp,15,4))
- response.write "<br/>#19-22 image width in pixels : "&binToNum(midB(temp,19,4))
- response.write "<br/>#23-26 image height in pixels : "&binToNum(midB(temp,23,4))
- response.write "<br/>#27-28 number of planes in the image, must be 1 : "&binToNum(midB(temp,27,1))
- response.write "<br/>#29-30 number of bits per pixel (1, 4, 8, or 24) : "&binToNum(midB(temp,29,1))
- response.write "<br/>#31-34 compression type (0=none, 1=RLE-8, 2=RLE-4) : "&binToNum(midB(temp,31,4))
- response.write "<br/>#35-38 size of image data in bytes (including padding) : "&binToNum(midB(temp,35,4))
- response.write "<br/>#39-42 horizontal resolution in pixels per meter (unreliable) : "&binToNum(midB(temp,39,4))
- response.write "<br/>#43-46 vertical resolution in pixels per meter (unreliable) : "&binToNum(midB(temp,43,4))
- response.write "<br/>#47-50 number of colors in image, or zero : "&binToNum(midB(temp,47,4))
- response.write "<br/>#51-54 number of important colors, or zero : "&binToNum(midB(temp,51,4))
- private function binToNum(bin)
- '二进制转为 Numeric
- dim i:binToNum=0
- for i=lenB(bin) to 1 step -1
- binToNum=binToNum*256+ascB(midB(bin,i,1))
- next 'shawl.qiu code'
- end function
- private function binToStr(bin)
- '二进制转为 string
- dim i, iByt, sByt, bLen:bLen=lenB(bin)
- for i=1 to bLen
- sByt=midB(bin,i,1):iByt=ascB(sByt)
- if iByt<128 then
- binToStr=binToStr&chr(iByt)
- else:i=i+1
- if i<=bLen then binToStr=binToStr&chr(ascW(sByt&sByt))
- end if
- next 'shawl.qiu'
- end function
- %>
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
ASP adodb.stream 取 Win32 .bmp 图片完整文件头信息 By shawl.qiu
最新推荐文章于 2017-12-02 20:34:21 发布