我要实现图片大小转换的问题,就是咱们常见的点击小图片显示原图的方法,我不知道怎么把原图压缩成小图还不改变效果.应该怎么解决啊大虾们?

解决方案 »

  1.   

    不用压缩吧只是用段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
      

  2.   

    这位仁兄的方法很好,在下表示感谢,但我还是觉得当image的大小比较大时,如2000*1000的,在显示小图时,虽然是按比例来缩小的,但我还是看到了失真(严重),请问,就只有这种方法了吗?还是你是否觉得没有必要处理这么大的图片呢?谢谢!!!
      

  3.   

    ...2000*1000,这个文件要 1M 以上大了吧。一般不会允许上传这么大的图片。不只上传时间久,容易传不上。到时候打开页面的时间也是很久的。网络慢点,网页就打不开了。一般我们做的都只允许上传100K以下的gif和jpg格式的图片。