| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1151 人关注过本帖
标题:[求助]求救。如何获得图片的信息
只看楼主 加入收藏
小小程序员
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-9-1
收藏
 问题点数:0 回复次数:5 
[求助]求救。如何获得图片的信息

在做电子相册的时候,要使图片显示在一个固定了宽、高的相框中,而不变型,请问高手们有何良策?我想获取这张图片的长宽,然后对应相框的宽高进行按比例缩放。可是又不只如何获取图片的宽高,也不知道如何使图片按某个比例来缩放。

搜索更多相关主题的帖子: 电子相册 相框 缩放 
2004-09-21 01:07
cime63
Rank: 1
等 级:新手上路
帖 子:167
专家分:0
注 册:2004-8-9
收藏
得分:0 

上传照片时,如果是用风声无组件上传类,可以得到照片高宽。还有,下面这个函数希望对你有帮助:

<% '********************************************************************************* ' ' graphic="help.gif" ' HW = ReadImg(graphic) ' Response.Write graphic & " Dimensions: " & HW(0) & "x" & HW(1) & "<br>" ' response.write "<img src=""/" & graphic & """" ' response.write height=""" & HW(0) & """ ' response.write width=""" & HW(0) & "">" ' '********************************************************************************** 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 %>

取图片尺寸函数


2004-09-21 08:28
cime63
Rank: 1
等 级:新手上路
帖 子:167
专家分:0
注 册:2004-8-9
收藏
得分:0 

<% Function ReSizeImage(SrcFile, SrcWidth, SrcHeight, MaxWidth, MaxHeight) WH = Array("", "")

if SrcFile = "" or SrcWidth = "" or SrcHeight = "" or MaxWidth = "" or MaxHeight = "" then Response.Write "参数错误" Response.End end if

OldP = SrcWidth / SrcHeight '原图象的宽高比例 ToWP = SrcWidth / MaxWidth '原图象的宽与新图象的宽比例 ToHP = SrcHeight / MaxHeight '原图象的高与新图象的高比例

if (MaxWidth < SrcWidth) or (MaxHeight < SrcHeight) then if ToWP > ToHP then ToW = MaxWidth ToH = MaxWidth / OldP else ToH = MaxHeight ToW = MaxHeight * OldP end if

WH(0) = ToW WH(1) = ToH else WH(0) = SrcWidth WH(1) = SrcHeight end if

ReSizeImage = WH End Function %>

图象成比例缩小函数


2004-09-21 08:28
cime63
Rank: 1
等 级:新手上路
帖 子:167
专家分:0
注 册:2004-8-9
收藏
得分:0 

在网上找到的,还没有测试。自己看看吧。希望对你有帮助。

还有,函数好不好用,请记得告诉我一声啊。谢谢了。


2004-09-21 08:29
cime63
Rank: 1
等 级:新手上路
帖 子:167
专家分:0
注 册:2004-8-9
收藏
得分:0 
还有,我记得我已经加你QQ了,怎么没有了?改名了?

2004-09-21 08:31
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
得分:0 
JS就可以得到图片的宽和高

天津网站建设 http://www./
2004-09-21 08:39
快速回复:[求助]求救。如何获得图片的信息
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012073 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved