FSO读取BMP,JPG,PNG,GIF图像文件信息的函数
作者:佚名 来源:蓝色理想 时间:2007-08-04 09:56:00
利用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
%>
标签:bmp,jpg,gif,fso,读取


猜你喜欢
Python应用实现处理excel数据过程解析
2022-10-24 11:52:17
numpy中hstack vstack stack concatenate函数示例详解
2023-02-22 19:39:06
vue修改滚动条样式的方法
2024-04-27 15:48:59

全网最新用python实现各种文件类型转换的方法
2021-02-21 08:57:42

python中yield的用法详解
2023-06-10 00:43:56
Flask使用Pyecharts在单个页面展示多个图表的方法
2021-10-12 18:16:35

网页设计经验谈
2007-10-30 13:11:00
七种Python代码审查工具推荐
2021-06-16 07:07:34
IE7新支持的CSS属性和属性选择符
2008-03-16 14:26:00
Python检查 云备份进程是否正常运行代码实例
2023-07-08 23:59:05
python入门之算法学习
2021-05-16 19:38:19
python库-dotenv包 及 .env配置文件详解
2023-09-08 20:22:38
pycharm利用pyspark远程连接spark集群的实现
2023-10-08 06:49:00

tensorflow -gpu安装方法(不用自己装cuda,cdnn)
2021-01-26 09:06:46
使用UglifyJS合并/压缩JavaScript的方法
2024-05-03 15:57:29

Python使用ClickHouse的实践与踩坑记录
2023-06-12 21:45:44

基于Python中numpy数组的合并实例讲解
2023-01-23 18:17:26

Go语言eclipse环境搭建图文教程
2024-05-09 09:47:36

CSS和HTML与前端技术层图示
2010-04-05 21:54:00

原生python实现knn分类算法
2023-04-18 14:07:52
