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
%>


猜你喜欢
- 前言相信大家在最近的chatGPT的注册或者使用过程中都遇到了很多很多的报错,接下来的内容是关于chatGPT不管是注册还是使用过程中所有报
- 什么情况下用响应缓冲会提高运行速度?例1、脚本引擎与 HTML 之间的切换频繁,对响应流写操作太多,导致性能下降:<table>
- 分页,就是按照某种规则显示分组数据集,但是在SQL Server 中,分页并不是十分容易就能够实现。在过去,开发人员通常需要自己编写程序,使
- 在JavaScript前端开发工作中,由于浏览器兼容性等问题,我们会经常用到“停止事件冒泡”和“阻止浏览器默认行为”。1..停止事件冒泡//
- 如下所示:import numpy as npimport pandas as pdfrom pandas import Series,Da
- 数据结构channel的数据结构在$GOROOT/src/runtime/chan.go文件下:type hchan struct {qco
- 其实canvas本身很简单,就是去学习它的API,多看实例,多自己动手练习,多总结。但是canvas的API实在是有点多,对于初学者来说,可
- TO_NUMBER(char[,'format_model']) 字符转换到数字类型TO_DATE(char[,'f
- 百度文库分享平台大家都知道,今天小编通过一段实例代码给大家介绍基于js实现百度文库评分功能,先给大家展示效果图吧。具体代码如下所示:<
- 本文实例为大家分享了js实现九宫格布局效果的具体代码,供大家参考,具体内容如下效果代码如下:<!DOCTYPE html><
- 第1关:Scatter:散点图(一)编程要求根据以上介绍,在右侧编辑器补充代码,绘制给定数据的散点图,要求:画布大小初始化为宽 1600 像
- numpy.mean计算矩阵均值计算矩阵的均值>>> a = np.array([[1, 2], [3, 4]])>
- 本文实例为大家分享了Django实现分页功能,为了容易区别功能的展现,先创建一个数据库,用数据库中的数据做演示。创建数据库步骤如下:1.创建
- python之所以被广泛使用,倒不见得是本身语法简单,而是而nodejs/javascript一样把三方库的依赖管理简化了,而不用和java
- 本文实例为大家分享了javascript不同颜色Tab标签切换效果的实现代码,供大家参考,具体内容如下具体代码:<html> &
- 一提到数字图像处理,可能大多数人就会想到matlab,但matlab也有自身的缺点:1、不开源,价格贵2、软件容量大。一般3G以上,高版本甚
- 本文实例为大家分享了python名片管理系统的开发代码,供大家参考,具体内容如下利用面向对象的开发方法,开发名片管理系统,要求用文件存储数据
- 系统:ubuntu18.04 x64GitHub:https://github.com/xingjidemimi/DjangoAPI.git
- 如何检测某个对象是否有某个属性?第一想到的——没错,in:"prop" in obj这很完美,不过,还有不少人热衷下面的
- 一、使用matplotlib显示图import matplotlib.pyplot as plt #plt用于显示图片import matp