上传时候,如何判断图片宽高 本帖最后由 xiaoshuang1990 于 2010-10-18 15:40:05 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <img src="demo.gif" onload="if(this.width>300)this.width=300">或者<script language="JavaScript"><!--//图片按比例缩放var flag=false;function DrawImage(ImgD,iwidth,iheight){//参数(图片,允许的宽度,允许的高度)var image=new Image();image.src=ImgD.src;if(image.width>0 && image.height>0){flag=true;if(image.width/image.height>= iwidth/iheight){if(image.width>iwidth){ ImgD.width=iwidth;ImgD.height=(image.height*iwidth)/image.width;}else{ImgD.width=image.width; ImgD.height=image.height;}ImgD.alt=image.width+"×"+image.height;}else{if(image.height>iheight){ ImgD.height=iheight;ImgD.width=(image.width*iheight)/image.height; }else{ImgD.width=image.width; ImgD.height=image.height;}ImgD.alt=image.width+"×"+image.height;}}} //--></script>调用:<img src="images/toplogo.gif" onload="javascript:DrawImage(this,100,100)"> 如果想在后台做,就需要首先上传然后BufferedImage bsrc = ImageIO.read(new File(filepath));int width = bsrc.getWidth();int height = bsrc.getHeight();但是这并没有避免上传,如果图片很大...我觉得在前台做好一点 题目如下 httpclient 执行execute()方法所耗时间过长,怎么解决? j2se关于args参数的一个问题 抓取图片 请给一些for循环的例子,处理什么问题的都行,长的短的都行!部分代码或者全代码也行! 如果获取数据库表结构? 一个奇怪的问题,急在线等 请问如下错误是怎麽回事? java sdk中的例子中 *.java 用写字板打开不能自动换行,不知它用什么文本编辑器? 什么是JBCL,我怎么看不见Frame UI中有这个选项卡 求助~~ 请教怎么获得 容器或组件 区域外的鼠标事件?
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
</script>
调用:<img src="images/toplogo.gif" onload="javascript:DrawImage(this,100,100)">
然后BufferedImage bsrc = ImageIO.read(new File(filepath));
int width = bsrc.getWidth();
int height = bsrc.getHeight();
但是这并没有避免上传,如果图片很大...
我觉得在前台做好一点