lt;%
Class ImgWHInfo '获取宽度和高度的类,支持JPG,GIF,PNG,BMP
Dim ASO
Private Sub Class_Initialize
Set ASO=ServerCreateObject("ADODBStream")
ASOMode=3
ASOType=1
ASOOpen
End Sub
Private Sub Class_Terminate
ErrClear
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)
ASOLoadFromFile(filespec)
bFlag=ASORead(3)
Select Case Hex(binVal(bFlag))
Case "4E5089":
ASORead(15)
ret(0)="PNG"
ret(1)=BinVal2(ASORead(2))
ASORead(2)
ret(2)=BinVal2(ASORead(2))
Case "464947":
ASOread(3)
ret(0)="gif"
ret(1)=BinVal(ASORead(2))
ret(2)=BinVal(ASORead(2))
Case "535746":
ASOread(5)
binData=ASORead(1)
sConv=Num2Str(ascb(binData),2 ,8)
nBits=Str2Num(left(sConv,5),2)
sConv=mid(sConv,6)
While(len(sConv)<nBits4)
binData=ASORead(1)
sConv=sConv&Num2Str(AscB(binData),2 ,8)
Wend
ret(0)="SWF"
ret(1)=Int(Abs(Str2Num(Mid(sConv,1nBits+1,nBits),2)-Str2Num(Mid(sConv,0nBits+1,nBits),2))/20)
ret(2)=Int(Abs(Str2Num(Mid(sConv,3nBits+1,nBits),2)-Str2Num(Mid(sConv,2nBits+1,nBits),2))/20)
Case "FFD8FF":
Do
Do: p1=binVal(ASORead(1)): Loop While p1=255 And Not ASOEOS
If p1>191 And p1<196 Then Exit Do Else ASOread(binval2(ASORead(2))-2)
Do:p1=binVal(ASORead(1)):Loop While p1<255 And Not ASOEOS
Loop While True
ASORead(3)
ret(0)="JPG"
ret(2)=binval2(ASORead(2))
ret(1)=binval2(ASORead(2))
Case Else:
If left(Bin2Str(bFlag),2)="BM" Then
ASORead(15)
ret(0)="BMP"
ret(1)=binval(ASORead(4))
ret(2)=binval(ASORead(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 = ServerCreateObject("ScriptingFileSystemObject")
If (FSOFileExists(IMGPath)) Then
Set IMGFile = FSOGetFile(IMGPath)
FileExt=FSOGetExtensionName(IMGPath)
Select Case FileExt
Case "gif","bmp","jpg","png":
Arr=GetImageSize(IMGFilePath)
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 = serverCreateObject("ScriptingFileSystemObject")
If (FSOFileExists(IMGPath)) Then
Set IMGFile = FSOGetFile(IMGPath)
FileExt=FSOGetExtensionName(IMGPath)
Select Case FileExt
Case "gif","bmp","jpg","png":
Arr=getImageSize(IMGFilePath)
imgH = Arr(2)
End Select
Set IMGFile=Nothing
Else
imgH = 0
End If
Set FSO=Nothing
End Function
End Class
IMGPath="Testjpg"
Set PP = New ImgWHInfo
W = PPimgW(ServerMappath(IMGPath))
H = PPimgH(ServerMappath(IMGPath))
Set pp = Nothing
ResponseWrite("<img src='"&IMGPath&"' border=0><br>宽:"&W&";高:"&H)
%>
<script>
var image = new Image();
imagesrc = '>
方法:用 >
String imageUrl=">
以上就是关于C语言中怎样获得jpg图片的宽和高全部的内容,包括:C语言中怎样获得jpg图片的宽和高、js 获取图片的高度和宽度问题、易语言怎样获取网络图片的尺寸等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)