一个关于图片大小转换问题,很简单,解决了就给分(50分) 我要实现图片大小转换的问题,就是咱们常见的点击小图片显示原图的方法,我不知道怎么把原图压缩成小图还不改变效果.应该怎么解决啊大虾们? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不用压缩吧只是用段Js把他按照一定的大小显示,长宽比例不失真;<script language="javascript" type="text/javascript">var flag=false; function DrawImage(ImgD){ var image=new Image(); var iwidth=100; //定义允许图片宽度 var iheight=100; //定义允许图片高度 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="caexpo_pic/letterPicture/<bean:write name='companyLetter' property='picture'/>" onload=DrawImage(this) border="0"> // 在img 用onload ,并且不要定义 width 和height 这位仁兄的方法很好,在下表示感谢,但我还是觉得当image的大小比较大时,如2000*1000的,在显示小图时,虽然是按比例来缩小的,但我还是看到了失真(严重),请问,就只有这种方法了吗?还是你是否觉得没有必要处理这么大的图片呢?谢谢!!! ...2000*1000,这个文件要 1M 以上大了吧。一般不会允许上传这么大的图片。不只上传时间久,容易传不上。到时候打开页面的时间也是很久的。网络慢点,网页就打不开了。一般我们做的都只允许上传100K以下的gif和jpg格式的图片。 用抽象类实现接口后,怎么通过接口调用抽象类里面实现的方法? TOMCAT 5的问题 如何跳转到以前的页面? 初试servlet,但是出现找不见错误 救命啊!!!如何在jsp页面中显示从数据库中获得的数据 已知一个文件的路径,如何在JSP里获取它然后传送的另一个地方,分数照饱给。。。。 servlet中如何保留session??? jsp文件中的window.open函数怎么用? 一个简单问题:如何用jsp或servlet得到浏览器类型 如何快速学会JavaWeb 紧急求助!!!jsp网站天天遭别人CC攻击,如果使用程序屏掉使用代理IP登陆我网站的人 jsp中三个charset的区别
<script language="javascript" type="text/javascript">var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth=100; //定义允许图片宽度
var iheight=100; //定义允许图片高度
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="caexpo_pic/letterPicture/<bean:write name='companyLetter' property='picture'/>" onload=DrawImage(this) border="0"> // 在img 用onload ,并且不要定义 width 和height