您的位置:首页技术开发ASP技巧 → 利用ASP获得图象的实际尺寸的示例

利用ASP获得图象的实际尺寸的示例

时间:2004/11/7 4:04:00来源:本站整理作者:蓝点我要评论(0)





dbtable.asp





<%

   graphic="images/learnaspiconmain.gif"

   HW = ReadImg(graphic)

   Response.Write graphic & " Dimensions: " & HW(0) & "x" & HW(1) & "
"

   response.write "
   response.write height=""" & HW(0) & """

   response.write width=""" & HW(0) & "">"

%>









The library that is included is:



<%

Dim HW



Function AscAt(s, n)

       AscAt = Asc(Mid(s, n, 1))

End Function



Function HexAt(s, n)

       HexAt = Hex(AscAt(s, n))

End Function





Function isJPG(fichero)

       If inStr(uCase(fichero), ".JPG") <> 0 Then

       isJPG = true

       Else

       isJPG = false

       End If

End Function





Function isPNG(fichero)

       If inStr(uCase(fichero), ".PNG") <> 0 Then

       isPNG = true

       Else

       isPNG = false

       End If

End Function





Function isGIF(fichero)

       If inStr(uCase(fichero), ".GIF") <> 0 Then

       isGIF = true

       Else

       isGIF = false

       End If

End Function





Function isBMP(fichero)

       If inStr(uCase(fichero), ".BMP") <> 0 Then

       isBMP = true

       Else

       isBMP = false

       End If

End Function





Function isWMF(fichero)

       If inStr(uCase(fichero), ".WMF") <> 0 Then

       isWMF = true

       Else

       isWMF = false

       End If

End Function





Function isWebImg(f)

       If isGIF(f) Or isJPG(f) Or isPNG(f) Or isBMP(f) Or isWMF(f) Then

       isWebImg = true

       Else

       isWebImg = true

       End If

End Function





Function ReadImg(fichero)

       If isGIF(fichero) Then

       ReadImg = ReadGIF(fichero)

       Else

       If isJPG(fichero) Then

       ReadImg = ReadJPG(fichero)

       Else

       If isPNG(fichero) Then

       ReadImg = ReadPNG(fichero)

       Else

       If isBMP(fichero) Then

       ReadImg = ReadPNG(fichero)

       Else

       If isWMF(fichero) Then

       ReadImg = ReadWMF(fichero)

       Else

       ReadImg = Array(0,0)

       End If

       End If

       End If

       End If

       End If

End Function





Function ReadJPG(fichero)

    Dim fso, ts, s, HW, nbytes

       HW = Array("","")

       Set fso = CreateObject("Scripting.FileSystemObject")

       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1)

       s = Right(ts.Read(167), 4)

       HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4))

       HW(1) = HexToDec(HexAt(s,1) & HexAt(s,2))

       ts.Close

    ReadJPG = HW

End Function





Function ReadPNG(fichero)

    Dim fso, ts, s, HW, nbytes

       HW = Array("","")

       Set fso = CreateObject("Scripting.FileSystemObject")

       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1)

       s = Right(ts.Read(24), 8)

       HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4))

       HW(1) = HexToDec(HexAt(s,7) & HexAt(s,8))

       ts.Close

    ReadPNG = HW

End Function





Function ReadGIF(fichero)

    Dim fso, ts, s, HW, nbytes

       HW = Array("","")

       Set fso = CreateObject("Scripting.FileSystemObject")

       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1)

       s = Right(ts.Read(10), 4)

       HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1))

       HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3))

       ts.Close

    ReadGIF = HW

End Function





Function ReadWMF(fichero)

    Dim fso, ts, s, HW, nbytes

       HW = Array("","")

       Set fso = CreateObject("Scripting.FileSystemObject")

       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1)

       s = Right(ts.Read(14), 4)

       HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1))

       HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3))

       ts.Close

    ReadWMF = HW

End Function





Function ReadBMP(fichero)

    Dim fso, ts, s, HW, nbytes

       HW = Array("","")

       Set fso = CreateObject("Scripting.FileSystemObject")

       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1)

       s = Right(ts.Read(24), 8)

       HW(0) = HexToDec(HexAt(s,4) & HexAt(s,3))

       HW(1) = HexToDec(HexAt(s,8) & HexAt(s,7))

       ts.Close

    ReadBMP = HW

End Function





Function isDigit(c)

       If inStr("0123456789", c) <> 0 Then

       isDigit = true

       Else

       isDigit = false

       End If

End Function





Function isHex(c)

       If inStr("0123456789ABCDEFabcdef", c) <> 0 Then

       isHex = true

       Else

       ishex = false

       End If

End Function





Function HexToDec(cadhex)

       Dim n, i, ch, decimal

       decimal = 0

       n = Len(cadhex)

       For i=1 To n

       ch = Mid(cadhex, i, 1)

       If isHex(ch) Then

       decimal = decimal * 16

       If isDigit(c) Then

       decimal = decimal + ch

       Else

       decimal = decimal + Asc(uCase(ch)) - Asc("A")

       End If

       Else

       HexToDec = -1

       End If

       Next

       HexToDec = decimal

End Function

%>




相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 VB.NET 2005编写定时关 Jquery get/post下乱码解决方法 前台gbk gb如何使用数据绑定控件显示数据ASP脚本循环语句ASP怎么提速

人气排行 轻松解决"Server Application Error"和iis"一起学习DataGridView调整列宽用ASP随机生成文件名的函数Jquery get/post下乱码解决方法 前台gbk gbODBC Drivers错误80004005的解决办法返回UPDATE SQL语句所影响的行数的方法用Javascript隐藏超级链接的真实地址两个不同数据库表的分页显示解决方案