佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > 獲取圖片寬度和高度的類,支持JPG,GIF,PNG,BMP

獲取圖片寬度和高度的類,支持JPG,GIF,PNG,BMP

熱門標(biāo)簽:銀行業(yè)務(wù) 服務(wù)器配置 團(tuán)購網(wǎng)站 Mysql連接數(shù)設(shè)置 阿里云 Linux服務(wù)器 科大訊飛語音識別系統(tǒng) 電子圍欄
%
Class ImgWHInfo ''獲取圖片寬度和高度的類,支持JPG,GIF,PNG,BMP
Dim ASO
Private Sub Class_Initialize
Set ASO=Server.CreateObject("ADODB.Stream")
ASO.Mode=3
ASO.Type=1
ASO.Open
End Sub
Private Sub Class_Terminate
Err.Clear
Set ASO=Nothing
End Sub

Private Function Bin2Str(Bin)
Dim I, Str
For I=1 To LenB(Bin)
clow=MidB(Bin,I,1)
If ASCB(clow)128 Then
Str = Str Chr(ASCB(clow))
Else
I=I+1
If I = LenB(Bin) Then Str = Str Chr(ASCW(MidB(Bin,I,1)clow))
End If
Next
Bin2Str = Str
End Function

Private 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

Private Function Str2Num(Str,Base)
Dim Ret,I
Ret = 0
For I=1 To Len(Str)
Ret = Ret *base + Cint(Mid(Str,I,1))
Next
Str2Num=Ret
End Function

Private Function BinVal(Bin)
Dim Ret,I
Ret = 0
For I = LenB(Bin) To 1 Step -1
Ret = Ret *256 + AscB(MidB(Bin,I,1))
Next
BinVal=Ret
End Function

Private Function BinVal2(Bin)
Dim Ret,I
Ret = 0
For I = 1 To LenB(Bin)
Ret = Ret *256 + AscB(MidB(Bin,I,1))
Next
BinVal2=Ret
End Function

Private Function GetImageSize(filespec)
Dim bFlag
Dim Ret(3)
ASO.LoadFromFile(filespec)
bFlag=ASO.Read(3)
Select Case Hex(binVal(bFlag))
Case "4E5089":
ASO.Read(15)
ret(0)="PNG"
ret(1)=BinVal2(ASO.Read(2))
ASO.Read(2)
ret(2)=BinVal2(ASO.Read(2))
Case "464947":
ASO.read(3)
ret(0)="gif"
ret(1)=BinVal(ASO.Read(2))
ret(2)=BinVal(ASO.Read(2))
Case "535746":
ASO.read(5)
binData=ASO.Read(1)
sConv=Num2Str(ascb(binData),2 ,8)
nBits=Str2Num(left(sConv,5),2)
sConv=mid(sConv,6)
While(len(sConv)nBits*4)
binData=ASO.Read(1)
sConv=sConvNum2Str(AscB(binData),2 ,8)
Wend
ret(0)="SWF"
ret(1)=Int(Abs(Str2Num(Mid(sConv,1*nBits+1,nBits),2)-Str2Num(Mid(sConv,0*nBits+1,nBits),2))/20)
ret(2)=Int(Abs(Str2Num(Mid(sConv,3*nBits+1,nBits),2)-Str2Num(Mid(sConv,2*nBits+1,nBits),2))/20)
Case "FFD8FF":
Do
Do: p1=binVal(ASO.Read(1)): Loop While p1=255 And Not ASO.EOS
If p1>191 And p1196 Then Exit Do Else ASO.read(binval2(ASO.Read(2))-2)
Do:p1=binVal(ASO.Read(1)):Loop While p1255 And Not ASO.EOS
Loop While True
ASO.Read(3)
ret(0)="JPG"
ret(2)=binval2(ASO.Read(2))
ret(1)=binval2(ASO.Read(2))
Case Else:
If left(Bin2Str(bFlag),2)="BM" Then
ASO.Read(15)
ret(0)="BMP"
ret(1)=binval(ASO.Read(4))
ret(2)=binval(ASO.Read(4))
Else
ret(0)=""
End If
End Select
ret(3)="width=""" ret(1) """ height=""" ret(2) """"
getimagesize=ret
End Function

Public Function imgW(IMGPath)
Dim FSO,IMGFile,FileExt,Arr
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
If (FSO.FileExists(IMGPath)) Then
Set IMGFile = FSO.GetFile(IMGPath)
FileExt=FSO.GetExtensionName(IMGPath)
Select Case FileExt
Case "gif","bmp","jpg","png":
Arr=GetImageSize(IMGFile.Path)
imgW = Arr(1)
End Select
Set IMGFile=Nothing
Else
imgW = 0
End If
Set FSO=Nothing
End Function

Public Function imgH(IMGPath)
Dim FSO,IMGFile,FileExt,Arr
Set FSO = server.CreateObject("Scripting.FileSystemObject")
If (FSO.FileExists(IMGPath)) Then
Set IMGFile = FSO.GetFile(IMGPath)
FileExt=FSO.GetExtensionName(IMGPath)
Select Case FileExt
Case "gif","bmp","jpg","png":
Arr=getImageSize(IMGFile.Path)
imgH = Arr(2)
End Select
Set IMGFile=Nothing
Else
imgH = 0
End If
Set FSO=Nothing
End Function
End Class
%>
%
IMGPath="Test.jpg"

Set PP = New ImgWHInfo
W = PP.imgW(Server.Mappath(IMGPath))
H = PP.imgH(Server.Mappath(IMGPath))
Set pp = Nothing
%>
%
Dim W,PXHeight
Dim Pp '//Proportion
If W=0 or W="" Then
PXWidth=0
PXHeight=0
Else
Pp=FormatNumber(W/H,2) '//長寬比
End If
If W>=H Then
If W>=300 Then
PXWidth=300
PXHeight=FormatNumber(300/Pp,0)
Else
PXWidth=W
PXHeight=H
End If
Else
If PHeight>=260 Then
PXHeight=260
PXWidth=FormatNumber(260*Pp,0)
Else
PXWidth=W
PXHeight=H
End If
End If
response.Write(PXWidth)
%>
img src="Test.jpg" border="0" width=%=PXWidth%>
height=%=PXHeight%>>
您可能感興趣的文章:
  • 混合語言編程—C#使用原生的Directx和OpenGL繪圖的方法
  • 使用OpenGL實(shí)現(xiàn)3D立體顯示的程序代碼
  • 通過OpenGL ES混合模式縮放視頻緩沖區(qū)來適應(yīng)顯示尺寸
  • 解決Vista系統(tǒng)OpenGL驅(qū)動(dòng)問題的方法整理
  • C語言讀取BMP圖像數(shù)據(jù)的源碼
  • sdl顯示一張bmp圖片示例
  • VC運(yùn)用OPENGL加載BMP紋理圖的實(shí)現(xiàn)方法匯總

標(biāo)簽:大理 萍鄉(xiāng) 江蘇 衡水 衢州 廣元 蚌埠 棗莊

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《獲取圖片寬度和高度的類,支持JPG,GIF,PNG,BMP》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    文安县| 余庆县| 曲沃县| 天门市| 临沧市| 阜南县| 搜索| 双柏县| 红河县| 磐安县| 离岛区| 靖西县| 昔阳县| 剑河县| 廊坊市| 桃源县| 东平县| 崇义县| 永昌县| 昌乐县| 奉节县| 海口市| 西乌| 南充市| 四川省| 清新县| 佛冈县| 南投市| 山丹县| 长治县| 广安市| 始兴县| 太原市| 革吉县| 浠水县| 家居| 曲阜市| 尚义县| 龙井市| 乐安县| 平武县|