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
 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值