用ASP怎么得到图片的尺寸大小? (100分)

Z

zhu-xz

Unregistered / Unconfirmed
GUEST, unregistred user!
是否要用到组件,具体方法?
 
zhu-xz,你把ASP看得太神了吧?我的理解就是ASP仅仅只有数据功能
 
???
不可能
 
是不是数据库里的?如果是,用recordset的actualsize看看!
 
我认为有可能,只是我现在还不知道方法.
请相信会有高手知道的.我先回去试一试.
 
JS中有Image对象,你可以在脚本操作它。
 
www.agenow.com 中就用asp实现了对图片大小的区分,可能也用到了一些第三方组件。
 
用HTTP的方式就可以了,通过读二进制流的方法,把相应的那段取出来就好了,不过
要注意分隔符就可以了.
tBytes = Request.TotalBytes(取的二进制流的全部大小)
binData = Request.BinaryRead(tBytes)
 
<<得到图片的尺寸大小
可以的 用 split
......
mydata=midb(filedata,datastart,dataend)
arrayMessage=split(checkImageFormat(mydata),",")
......
arrayMessage(1) 长
arrayMessage(2) 宽

下面是源程序
SavePic.asp
<%
'---------------------------------------RETURN THE IMAGE FORMAT--------------------
function checkImageFormat(checkdata)
'--return: A,B,C (A is image format;
B is height pixels;
C is width pixels;
D is color depth)
flag=0 '''''''0 is not jpg/gif/png image;
1 is jpg/gif/png

'-------------------------------------------------------check jpg----------------
if flag=0 then

tempstr=Leftb(checkdata,10)
tstr=chrb(255)&amp;chrb(216)&amp;chrb(255)&amp;chrb(224)&amp;chrb(0)&amp;chrb(16)&amp;chrb(74)&amp;chrb(70)&amp;chrb(73)&amp;chrb(70)
if strcomp(tempstr,tstr,0)=0 then
msgstr01="jpg"
lngSize = len(checkdata)
flgFound = 0

strTarget = chrb(255) &amp;
chrb(216) &amp;
chrb(255)
flgFound = instrb(checkdata, strTarget)
lngPos = flgFound + 2
ExitLoop = false
do
while ExitLoop = False and lngPos < lngSize
do
while ascb(midb(checkdata, lngPos, 1)) = 255 and lngPos < lngSize
lngPos = lngPos + 1
loop
if ascb(midb(checkdata, lngPos, 1)) < 192 or ascb(midb(checkdata, lngPos, 1)) > 195 then
lngMarkerSize = lngConvert2(midb(checkdata, lngPos + 1, 2))
lngPos = lngPos + lngMarkerSize + 1
else
ExitLoop = True
end if
loop
i_Height = lngConvert2(midb(checkdata, lngPos +4, 2))
i_Width = lngConvert2(midb(checkdata, lngPos +6, 2))
i_Depth = 2 ^ (ascb(midb(checkdata, lngPos + 8, 1)) * 8)

msgstr02=","&amp;
i_height &amp;
"," &amp;
i_width
flag=2
else
flag=0
end if

end if
'--------------------------------------------------check gif--------------------------------
if flag=0 then
tempstr=Leftb(checkdata,6)
tstr=chrb(71)&amp;chrb(73)&amp;chrb(70)&amp;chrb(56)&amp;chrb(57)&amp;chrb(97)
tstr2=chrb(71)&amp;chrb(73)&amp;chrb(70)&amp;chrb(56)&amp;chrb(55)&amp;chrb(97)
if strcomp(tempstr,tstr,0)=0 or strcomp(tempstr,tstr2)=0 then
msgstr03="gif"

i_width=lngConvert(midb(checkdata,7,2))
i_height=lngConvert(midb(checkdata,9,2))
i_Depth = 2 ^ ((ascb(midb(checkdata, 11, 1)) and 7) + 1)
msgstr04=","&amp;
i_height &amp;
","&amp;
i_width

flag=2
else

flag=0
end if
end if
'---------------------------------------------------check png------------------------------
if flag=0 then

tempstr=Leftb(checkdata,4)
tstr=chrb(137)&amp;chrb(80)&amp;chrb(78)&amp;chrb(71)
if strcomp(tempstr,tstr,0)=0 then
msgstr05="png"

i_Width = lngConvert2(midb(checkdata, 19, 2))
i_Height = lngConvert2(midb(checkdata, 23, 2))
i_Depth = lngConvert(midb(checkdata, 25, 2))
select case ascb(right(i_Depth,1))
case 0
i_Depth = 2 ^ (asc(left(i_Depth, 1)))
gfxSpex = True
case 2
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 3)
gfxSpex = True
case 3
i_Depth = 2 ^ (asc(left(i_Depth, 1))) '8
gfxSpex = True
case 4
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 2)
gfxSpex = True
case 6
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 4)
gfxSpex = True
case else
i_Depth = -1
end select
msgstr06=","&amp;
i_height &amp;
","&amp;
i_width
flag=2
else

flag=0
end if
end if
if flag=0 then

msgstr07="no image"
end if
msgstr=msgstr01 &amp;
msgstr02 &amp;
msgstr03 &amp;
msgstr04 &amp;
msgstr05 &amp;
msgstr06 &amp;
msgstr07
checkImageFormat=msgstr
end function
function lngConvert2(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
lngConvert2 = clng(ascb(str2) + ((ascb(str1) * 256)))
end function
function lngConvert(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
len1=ascb(str1)
len2=ascb(str2)
lngConvert = clng(ascb(str1) + ascb(str2) * 256)
end function
'------------------------Copyright by qinls------------------
%>


<%
Response.buffer=true '将服务端传送给缓冲区
filesize=Request.totalbytes '客户端响应数据字节的大小
filedata=Request.binaryread(filesize) '得到数据量要小于或等于totalbytes


'*******得到有效的图片的信息*********
bncrlf=chrB(13) &amp;
chrB(10)
divider=leftB(filedata,clng(instrB(filedata,bncrlf))-1)
datastart=instrb(filedata,bncrlf &amp;
bncrlf)+4
dataend=instrb(datastart+1,filedata,divider)-datastart '(搜索的起点,字符串1,字符串2)
mydata=midb(filedata,datastart,dataend)
arrayMessage=split(checkImageFormat(mydata),",")
'*********************************
%>
<% if arrayMessage(1)>150 OR arrayMessage(2)>100 then
%>
<script language="javascript">
alert("您所选择的图片的尺寸不符合要求!应在 高*宽 150*100 之间")
window.location="SP.htm"
</script>
<% else
Set Cn=server.CreateObject("ADODB.connection")
Cn.ConnectionString="Driver={Microsoft Access Driver (*.mdb)};DBQ=" &amp;
Server.MapPath("pic.mdb")
Cn.Open
Set Rs=Server.createobject("ADODB.Recordset")
Rs.Open "SELECT * FROM T1 where ID is Null",Cn,1,3
Rs.Addnew
Rs.Fields("IMG").appendchunk mydata
Rs.Update
Rs.Close
Set Rs=nothing
Set Cn=nothing
End if
%>
<script language="Javascript">
window.location="SP.htm"
</script>

'&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;

SearchPic.asp
<script language="javascript">
</script>
<%
Set Cn=server.CreateObject("ADODB.connection")
Cn.ConnectionString="Driver={Microsoft Access Driver (*.mdb)};DBQ=" &amp;
server.MapPath("pic.mdb")
Cn.Open
Set Rs=Server.Createobject("ADODB.Recordset")
Sql="SELECT * from T1"
Rs.open Sql,Cn,2,3
Response.Write "<table width=""100%"" cellspacing=""0"" cellpadding=""0"" border=""2"" bordercolor=""#CCCCCC"" align=""center"">"
Do While NOT Rs.EOF
Response.Write "<tr>"
Response.Write "<td>"
Response.Write trim(Rs.Fields("ID"))
Response.Write "</td>"
Numberimg=Rs.Fields("ID")
Response.Write "<td>"
Response.Write "<IMG SRC=""ShowPic.asp?ID=" &amp;
Numberimg &amp;
""">"
Response.Write "</td>"
Rs.MoveNext
Response.Write "</tr>"
Loop
Response.Write "</table>"%>
<% Response.Write "<P></P>" %>
<input type="button" value="继续上传图片" onclick="window.location='SP.htm'">
<%Rs.Close
Cn.Close
%>

'&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;
SeeBig.asp
<HTML>
<BODY >
<input type="image" name="img1" SRC= <%=Request("FFF") %> >
</BODY>
</HTML>

'&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;
ShowPic.asp

<%
Set Cn=server.CreateObject("ADODB.connection")
Cn.ConnectionString="Driver={Microsoft Access Driver (*.mdb)};DBQ=" &amp;
server.MapPath("pic.mdb")
Cn.Open
Set Rs=Server.Createobject("ADODB.recordset")
Sql="SELECT IMG from T1 WHERE ID=" &amp;
Request("ID")
Rs.open Sql,Cn,1,1
Response.ContentType = "image/*"
Response.BinaryWrite Rs("IMG").getChunk(7500000)
Rs.Close
Set Rs=nothing
Set Cn=nothing
%>
'&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;
SP.htm

<html>
<head>
<script language="JavaScript">
function See(hh,ff) {
hh.src=ff.value
}
function SeeBig(filepath){
window.open("SeeBig.asp?FFF="+filepath,"","");
}
</Script>
</head>
<body>
<form name="f1" enctype="multipart/form-data" action="SavePic.asp" method=post>
<input type=file name="file1">
<input type="button" name="b1" value="预览" onClick="See(this.form.picview,this.form.file1)" >
<input type=submit name="upfile" value="上传">
<br>
<img src="image/view.JPG" name="picview" width="100" height="120" Border="0" alt="单击放大" onClick="SeeBig(file1.value)">
</form>
<form name="f2" action="SearchPic.asp" method="post">
<input type="submit" name="s2" value="查看所有上传图片">
</form>
</body>
</html>
 
>> sportsman,
ShowPic.asp
根本就显示不出来图片呀,浏览器就不动了,什么都没有,光标总是等待状态!

 
不会吧,我尝试过,可以的。
数据库(access)做好了吗?放在根目录下。
 
好了,和asp文件在一个目录下,可是只能上传到数据库,但不能显示,总是等待状态。
图像类型:OLE
 
把文件上传到服务器后,然后用组件判断。
我做的多媒体管理系统就是这样做的。
 
发非法信息
 
用FSO可以得到文件的大小的,网上有很多这样的例子
 
先建一个htm文件名为up.htm,代码如下
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 2</title>
</head>
<body>
<form action="up.asp" ENCTYPE="multipart/form-data" method="post">
<table border=0 width=100% cellspacing="0">
<tr>
<td width="30%">请选择您要上传的gif图片:</td>
<td width="70%"><input input type="file" name="pic"
style="font-size:10pt;"></td>
</tr> </table>
<p align="center"><input type="submit" value="提交"
style="font-size:9pt;background-color:#54B060;color:white;">
</form>
</body>
</html>
再建一个asp文件,名为up.asp,代码如下
<%
FormSize = Request.TotalBytes
FormData = Request.BinaryRead( FormSize )
bncrlf=chrb(13) &amp;
chrb(10)
divider=leftb(formdata,instrb(formdata,bncrlf)-1)
datastart=instrb(formdata,bncrlf &amp;
bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
Image=midb(formdata,datastart,dataend)
head_version = Ascb( midb( Image,1,3 ) )
head_subversion = Ascb( midb( Image,4,3 ) )
head_width_l = Ascb( midb( Image,7,1 ) )
head_width_h = Ascb( midb( Image,8,1 ) )
head_height_l = Ascb( midb( Image,9,1 ) )
head_height_h = Ascb( midb( Image,10,1 ) )
head_colors = Ascb( midb( Image, 11, 1 ) )
head_width_h = head_width_h * 256
head_height_h = head_height_h * 256

head_colors = head_colors And &amp;H07
Response.Write "图像大小为" &amp;
head_width_h + head_width_l &amp;
"x" &amp;_
head_height_h + head_height_l _
&amp;
"x" &amp;
2^( head_colors + 1 )
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 2</title>
</head>
<body>
</body>
</html>
 
顶部