您的位置: 首页 N搜咨询 文章阅读 利用FSO取得BMP,JPG,PNG,GIF文…
打印本页 放大字体 关闭本页
利用FSO取得BMP,JPG,PNG,GIF文件信息

作者:N搜网友 编辑:N搜网 录入:N搜网 来源:N搜网络
录入时间:2006-9-29 更新时间:2006-9-29 点击次数:608
主标题:利用FSO取得BMP,JPG,PNG,GIF文件信息
副标题:利用FSO取得BMP,JPG,PNG,GIF文件信息
短标题:利用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 :::
’::: :::
’:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function GetBytes(flnm, offset, bytes)
Dim objFSO
Dim objFTemp
Dim objTextStream
Dim lngSize
on error resume next
Set objFSO = CreateObject("Scripting.FileSystemObject")

’ First, we get the filesize
Set objFTemp = objFSO.GetFile(flnm)
lngSize = objFTemp.Size
set objFTemp = nothing
fsoForReading = 1
Set objTextStream = objFSO.OpenTextFile(flnm, fsoForReading)
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)
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)))
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:
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 & " colors"
else
response.write " "
end if
response.write "</td></tr>"
end if
Next
response.write "</table>"
set objFC = nothing
set objF = nothing
set objFSO = nothing

%>

N搜网-中国网上商店商品服务搜索门户]:[本文章由N搜网于2006-9-29录入系统,网址:www.nsall.com

打印本页 放大字体 关闭本页
 
 
相关主题文章
一些常用的正则表达式 紫雨轩IIS URL 重写组件 V1.0 [组图]
17种正则表达式 IIS实现ASP,CGI,PERL和PHP+MYSQL [组图]
WEB打印大全 关闭窗口时保存数据的办法
17种正则表达式 用正则解析图片地址,并利用XMLHTTP组件将其保存
利用ASP+JMAIL进行邮件群发的新思路 用ASP实现对ORACLE数据库的操作
ASP操作Excel技术总结 LCID地区代码
实现搜索结果的关键词变色标注的程序 IIS6.0下ASP的新增功能
浅谈如何建立三层体系结构的ASP应用程序 判断Cookies是否处于开启状态
验证码的程序及原理 在线实时开通WEB及FTP源程序 [组图]
vbs(asp)的栈类 用ASP打开远端MDB文件的方法
巧用ASP生成PDF文件 利用FSO取得BMP,JPG,PNG,GIF文件信息
远程获取内容,并将内容存在本地电脑上,包括任何… 三种禁用FileSystemObject组件的方法
js的单元格颜色间隔 一个不需要第三方组件,可实现华简单图形的类
asp实现k线图(在线) 用InstallShield 进行 ASP 软件的打包和自动安装…
如何在服务器端调用winzip命令行对上传的多个文件… 构建免受 FSO 威胁虚拟主机 [组图]
如何正确显示数据库中的图片 远程注册自己的组件
asp提高首页性能的一个技巧 Flash和Asp数据库的结合应用
ASP小偷(远程数据获取)程序的入门教程 [组图] 一个采集入库生成本地文件的几个FUCTION
asp编写的加密和解密类 不能使用asp标记的时候的一个解决办法
ASP无组件上传进度条解决方案 ASP中也能解压缩rar文件 [组图]
ASP做象资源管理器的树形目录 ASP文件上传原理分析及实现实例
一个通用的保护ASP系统的方法 编写安全的ASP代码
ASP ActiveX 组件 连接数据库查询手册
用ASP实现在线压缩与解压缩 ASP能读写注册表
xmlHTTP技术资料 ASP小偷(远程数据获取)程序入门教程
ASP网站漏洞解析及黑客入侵防范方法 轻松实现将上传图片到数据库
ASP编码优化 最简洁的多重查询的解决方案
无组件实现文件上传/下载 ASP漏洞全接触-高级篇
ASP漏洞全接触-入门篇 ASP技术访问WEB数据库
自动获得远程图片 #Writ 获得远程的文件,获得远程HTML文件源码
CDONTS和Jmail的使用 使用ASP生成图片彩色校验码
用ASP制作饼图、柱状图等 [组图] ASP生成静态页面的方法
asp组件上传 ASP中利用OWC控件实现图表功能详解 [组图]
用asp自动解析网页中的图片地址,并将其保存到本… 常用ASP自定义函数集
在ASP中用“正则表达式对象”来校验数据的合法性… ASP中正则表达式的应用
ASP面向对象编程探讨及比较 在ASP文件中调用DLL
C++中的虚函数(virtual function) C语言初学者入门讲座 第二讲 数据类型(1)
C语言初学者入门讲座 第二讲 数据类型(2) C语言初学者入门讲座 第二讲 数据类型(3)
利用VC++编写Windows95的CPL组件 调试Release版本应用程序
利用VC++开发ASP图像处理组件 如何在ASP.Net 中把图片存入数据库
用ASP实现的2000年倒记时程序 用VB6分离出文本框的单词
在ASP中用“正则表达式对象”来校验数据的合法性… 用ASP实现网上考试系统
在ASP中利用“正则表达式” 对象实现UBB风格… [组图] 在Asp.Net中从sqlserver检索(retrieve)图片
消息队列在VB.NET数据库开发中的应用 在PowerBuilder中调用ChooseColor函数
在PB中应用灵活多样的排序 用C#编写获取远程IP,MAC的方法
如何在ASP程序中打印Access报表 用Vb.net实现自定义界面
使用C#编写扩展存储过程 Java平台上的CRM系统
VB.NET开发扫描客户端服务工具 Visual Basic.Net连各种数据库的几种方法
JSP数据库连接方式总结 如何选购虚拟主机
什么是虚拟主机? 虚拟主机优点有那些?
 
 
 
本站关键字:网上商店商品服务大全 网上购物导航 在线购物搜索引擎 网店比较购物 网络商城 特色网上超市商店 网上网络开店购物