网络编程
位置:首页>> 网络编程>> Asp编程>> FSO读取BMP,JPG,PNG,GIF图像文件信息的函数

FSO读取BMP,JPG,PNG,GIF图像文件信息的函数

作者:佚名 来源:蓝色理想 发布时间:2007-08-04 09:56:00 

标签:bmp,jpg,gif,fso,读取

利用FSO取得BMP,JPG,PNG,GIF文件信息:大小,宽、高尺寸等 


’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
’::: BMP, GIF, JPG and PNG :::
’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
’::: :::
’::: This function gets a specified number of bytes from any :::
’::: file, starting at the offset (base 1) :::
’::: :::
’::: Passed: :::
’::: flnm => Filespec of file to read :::
’::: offset => Offset at which to start reading :::
’::: bytes => How many bytes to read :::
’::: 翻译注释:asp之家 www.aspxhome.com
’水平有限很多没看懂,不好意思,呵呵:
’::: 功能:获取文件大小,
’::: 参数:flnm=>文件路径,offset=>好像这个没什么意义,bytes =>读取指定大小
’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function GetBytes(flnm, offset, bytes)
Dim objFSO
Dim objFTemp
Dim objTextStream
Dim lngSize
on error resume next
Set objFSO = CreateObject("Scripting.FileSystemObject")
’ 首先,我们获取文件尺寸
Set objFTemp = objFSO.GetFile(flnm)
’GetFile返回一个和指定路径中文件相对应的 File 对象
lngSize = objFTemp.Size
set objFTemp = nothing
fsoForReading = 1
’以只读模式打开文件。不能对此文件进行写操作。
Set objTextStream = objFSO.OpenTextFile(flnm, fsoForReading)
’OpenTextFile打开指定的文件并返回一个 TextStream 对象,可以读取、写入此对象或将其追加到文件
if offset > 0 then
strBuff = objTextStream.Read(offset - 1)
end if
if bytes = -1 then ’ Get All!
GetBytes = objTextStream.Read(lngSize) ’ReadAll
’读取所有
else
GetBytes = objTextStream.Read(bytes)
’读取并返回指定bytes的字符数
end if
objTextStream.Close
set objTextStream = nothing
set objFSO = nothing
end function 



’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
’::: :::
’::: Functions to convert two bytes to a numeric value (long) :::
’::: (both little-endian and big-endian) :::
’::: :::
’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function lngConvert(strTemp)
lngConvert = clng(asc(left(strTemp, 1)) + ((asc(right(strTemp, 1)) * 256)))
’asc()返回与字符串的第一个字母对应的 ANSI 字符代码,如a是97
end function
function lngConvert2(strTemp)
lngConvert2 = clng(asc(right(strTemp, 1)) + ((asc(left(strTemp, 1)) * 256)))
end function



’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
’::: :::
’::: This function does most of the real work. It will attempt :::
’::: to read any file, regardless of the extension, and will :::
’::: identify if it is a graphical image. :::
’::: :::读取所有图形文件
’::: Passed: :::
’::: flnm => Filespec of file to read :::文件路径
’::: width => width of image :::图片宽
’::: height => height of image :::图片高
’::: depth => color depth (in number of colors) :::  色彩深度 
’::: strImageType=> type of image (e.g. GIF, BMP, etc.) :::文件类型
’::: :::
’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


function gfxSpex(flnm, width, height, depth, strImageType)
dim strPNG 
dim strGIF
dim strBMP
dim strType
strType = ""
strImageType = "(unknown)"
gfxSpex = False
strPNG = chr(137) & chr(80) & chr(78)
strGIF = "GIF"
strBMP = chr(66) & chr(77)
strType = GetBytes(flnm, 0, 3)
if strType = strGIF then ’ is GIF
strImageType = "GIF"
Width = lngConvert(GetBytes(flnm, 7, 2))
Height = lngConvert(GetBytes(flnm, 9, 2))
Depth = 2 ^ ((asc(GetBytes(flnm, 11, 1)) and 7) + 1)
gfxSpex = True
elseif left(strType, 2) = strBMP then ’ is BMP
strImageType = "BMP"
Width = lngConvert(GetBytes(flnm, 19, 2))
Height = lngConvert(GetBytes(flnm, 23, 2))
Depth = 2 ^ (asc(GetBytes(flnm, 29, 1)))
gfxSpex = True
elseif strType = strPNG then ’ Is PNG
strImageType = "PNG"
Width = lngConvert2(GetBytes(flnm, 19, 2))
Height = lngConvert2(GetBytes(flnm, 23, 2))
Depth = getBytes(flnm, 25, 2)
select case asc(right(Depth,1))
case 0
Depth = 2 ^ (asc(left(Depth, 1)))
gfxSpex = True
case 2
Depth = 2 ^ (asc(left(Depth, 1)) * 3)
gfxSpex = True
case 3
Depth = 2 ^ (asc(left(Depth, 1))) ’8
gfxSpex = True
case 4
Depth = 2 ^ (asc(left(Depth, 1)) * 2)
gfxSpex = True
case 6
Depth = 2 ^ (asc(left(Depth, 1)) * 4)
gfxSpex = True
case else
Depth = -1
end select 
else
strBuff = GetBytes(flnm, 0, -1) ’ Get all bytes from file
lngSize = len(strBuff)
flgFound = 0
strTarget = chr(255) & chr(216) & chr(255)
flgFound = instr(strBuff, strTarget)
if flgFound = 0 then
exit function
end if
strImageType = "JPG"
lngPos = flgFound + 2
ExitLoop = false
do while ExitLoop = False and lngPos < lngSize
do while asc(mid(strBuff, lngPos, 1)) = 255 and lngPos < lngSize
lngPos = lngPos + 1
loop
if asc(mid(strBuff, lngPos, 1)) < 192 or asc(mid(strBuff, lngPos, 1)) > 195 then
lngMarkerSize = lngConvert2(mid(strBuff, lngPos + 1, 2))
lngPos = lngPos + lngMarkerSize + 1
else
ExitLoop = True
end if
loop

if ExitLoop = False then
Width = -1
Height = -1
Depth = -1
else
Height = lngConvert2(mid(strBuff, lngPos + 4, 2))
Width = lngConvert2(mid(strBuff, lngPos + 6, 2))
Depth = 2 ^ (asc(mid(strBuff, lngPos + 8, 1)) * 8)
gfxSpex = True
end if
end if
end function



<%
’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
’::: Test Harness :::测试例子
’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
’ To test, we’ll just try to show all files with a .GIF extension in the root of C:
’读取c盘的所有扩展名是GIF的图像文件,
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objF = objFSO.GetFolder("c:\")
Set objFC = objF.Files
response.write "<table border=""0"" cellpadding=""5"">"
For Each f1 in objFC
if instr(ucase(f1.Name), ".GIF") then '如果想获取其它格式的图像信息就改这里
response.write "<tr><td>文件名:" & f1.name & "</td><td>文件创建时间:" & f1.DateCreated & "</td><td>" & f1.Size & "字节</td><td>尺寸:"
if gfxSpex(f1.Path, w, h, c, strType) = true then
response.write w & " x " & h & " 色彩:" & c & " 色"
else
response.write " "
end if
response.write "</td></tr>"
end if
Next
response.write "</table>"
set objFC = nothing
set objF = nothing
set objFSO = nothing
%>


0
投稿

猜你喜欢

  • [参与测试的浏览器:IE6 / IE7 / IE8 / FF3 / OP9.6 / SF3 / Chrome2 ][操作系统:Windows
  • 网站的改版和重新设计总是一件让人激动的事情,上到老板,下到设计师。更漂亮!更强大!更人性化……参与设计者一定有着无数为新版本骄傲的理由,然后
  • 网页制作中用到的特效字,你一定是用图象处理软件制作的吧!告诉你,不用图象处理软件,我也能做出漂亮的特效字来,你看,阴影字我就是这样做出来的。
  • 1.建立Recordset对象 代码如下:Dim objMyRst Set objMyRst=Server.C
  • 随滚动条移动的DIV层js代码,无论你的滚动条到哪里这个DIV层就跟到哪里!代码中例举了五个方向的滚动div层例子:包括左上方的div,左下
  • javascript编写的窗口代码,可以关闭显示窗口,可以最小化或还原窗口大小,还可以鼠标移动窗口,不错的一个功能。截图如下:<htm
  • 数据库的使用过程中由于程序方面的问题有时候会碰到重复数据,重复数据导致了数据库部分设置不能正确设置……方法一以下为引用的内容:declare
  • 平时我们在使用MySQL数据库的时候经常会因为操作失误造成数据丢失,MySQL数据库备份可以帮助我们避免由于各种原因造成的数据丢失或着数据库
  • 阅读上一篇:W3C优质网页小贴士(二) 注意字体大小网页设计者中有这么一种倾向:他们认为小字体能让网页看起来更漂亮,并能提供更多空间给每个网
  • Variant变量一般会将其代表的数据子类型自动转换成合适的数据类型,但有时候,自动转换也会造成一些数据类型不匹配的错误.这时,可使用转换函
  • 原来的语句是这样的: select sum(sl0000) from xstfxps2 where dhao00 in ( select d
  • 内容摘要:除了内部性能增强和优化外,IIS6.0版本的 Active Server Pages(ASP)&nb
  • 每个写asp程序人必会的知识!在ASP编程中使用数组数组的定义Dim MyArrayMyArray = Array(1,5,123,12,9
  • 继团队的CSS3.0中文手册在国内首发以后,最近风风火火的到处吹起HTML5.0和CSS3.0的春风;似乎在这浏览器互相调侃的年代,成就了一
  • 通过HTTP_USER_AGENT判断用户是从手机上访问,还是电脑IE上访问。 asp代码片段:主要使用了正则匹配手机环境,大家可以补充手机
  • 用语言实现 好处: 1、可以减少对数据库的访问。 2、可移植性好。 坏处: 1、操作起来考虑的东西较多,修改一处就要修改别一处。也就是说是相
  • 先来看看js中的Null类型表示什么?null用来表示尚未存在的对象,常用来表示函数企图返回一个不存在的对象,一般一个未定义的变量在初次使用
  • 最近在工作当中遇到一个问题 有个页面需要添加一个浏览历史记录功能具体来说就是要记录下用户在此网站的点击历史 并把它们降序排列出来(只显示前6
  • 编写兼容IE和FireFox的脚本确定的件很烦人的事,今日又经历了一次。一、正式表达式问题试图用以下表达式提取中括号“]”后面的内容,连接调
  • 没事在这里发一下关于数据库大批量插入数据的效率对比,用ACCESS和MSSQL,数值是在本机测试,根据不同的环境和配置,数值可能会有较大差别
手机版 网络编程 asp之家 www.aspxhome.com