發表于:2010-12-03 00:00:00來源:EyNet人氣:3341
取得圖像的屬性函數如下(xià):
'函數名:GetImageDx
'作 用:取得圖像的屬性:類型、寬、高
'參 數:filepath ---- 文件路徑及文件命名
'返回值:"類型|寬|高"
'**************************************************''''
Public Function GetImageDx(ByVal filepath)
DIM Tempsm,NBxx,WJXX(3)
SET Tempsm = Server.CreateObject("ADODB.Stream")
Tempsm.Mode=3
Tempsm.Type=1
Tempsm.Open
Tempsm.LoadFromFile filepath
NBxx=Hex(BinVal(Tempsm.Read(3)))
WJXX(0)=NBxx
WJXX(1)="0"
WJXX(2)="0"
If NBxx="464947" Then
WJXX(0)="GIF"
Tempsm.Read(3)
WJXX(1)=BinVal(Tempsm.Read(2))
WJXX(2)=BinVal(Tempsm.Read(2))
End If
If NBxx="FFD8FF" Then
WJXX(0)="JPG"
do
do: p1=binVal(Tempsm.Read(1)): loop while p1=255 and not Tempsm.EOS
if p1>191 and p1<196 then exit do else Tempsm.Read(binval2(Tempsm.Read(2))-2)
do:p1=binVal(Tempsm.Read(1)):loop while p1<255 and not Tempsm.EOS
loop while true
Tempsm.Read(3)
WJXX(2)=binval2(Tempsm.Read(2))
WJXX(1)=binval2(Tempsm.Read(2))
End If
If Mid(NBxx,3)="4D42" Then
Tempsm.Read(15)
WJXX(0)="BMP"
WJXX(1)=binval(Tempsm.Read(4))
WJXX(2)=binval(Tempsm.Read(4))
End If
If NBxx="4E5089" Then
WJXX(0)="PNG"
Tempsm.Read(15)
WJXX(1)=BinVal2(Tempsm.Read(2))
Tempsm.Read(2)
WJXX(2)=BinVal2(Tempsm.Read(2))
End If
If NBxx="535743" Then
WJXX(0)="SWF"
Tempsm.Read(5)
binData=Tempsm.Read(1)
sConv=Num2Str(ascb(binData),2 ,8)
nBits=Str2Num(left(sConv,5),2)
sConv=mid(sConv,6)
while(len(sConv)<nBits*4)
binData=Tempsm.Read(1)
sConv=sConv&Num2Str(ascb(binData),2 ,8)
wend
WJXX(1)=int(abs(Str2Num(mid(sConv,1*nBits+1,nBits),2)-Str2Num(mid(sConv,0*nBits+1,nBits),2))/20)
WJXX(2)=int(abs(Str2Num(mid(sConv,3*nBits+1,nBits),2)-Str2Num(mid(sConv,2*nBits+1,nBits),2))/20)
End If
Tempsm.Close
SET Tempsm=nothing
GetImageDx = WJXX(0)&"|"&WJXX(1)&"|"&WJXX(2)
End Function
Function BinVal(bin)
dim ret
ret = 0
for i = lenb(bin) to 1 step -1
ret = ret *256 + ascb(midb(bin,i,1))
next
BinVal=ret
End Function
Function BinVal2(bin)
dim ret
ret = 0
for i = 1 to lenb(bin)
ret = ret *256 + ascb(midb(bin,i,1))
next
BinVal2=ret
End Function
Function Str2Num(str,base)
dim ret
ret = 0
for i=1 to len(str)
ret = ret *base + cint(mid(str,i,1))
next
Str2Num=ret
End Function
Function Num2Str(num,base,lens)
dim ret
ret = ""
while(num>=base)
ret = (num mod base) & ret
num = (num - num mod base)/base
wend
Num2Str = right(string(lens,"0") & num & ret,lens)
End Function