比如说网站上面有一张图片,这个图片的大小,可以让用户自己设置,但是会出现这样的情况,在这张图片大小改动比较大的时候,画质就会发生改变!会变得看不清楚,有没有方法可以无论用户如何改大小,这个图片的画质都和开始的一样清晰呢?不知道我有没有表达清楚还请各位指教

解决方案 »

  1.   

    通过等比例缩放图片
    function DrawImage(ImgD,FitWidth,FitHeight){
         var image=new Image();
         image.src=ImgD.src;
         if(image.width>0 && image.height>0){
             if(image.width/image.height>= FitWidth/FitHeight){
                 if(image.width>FitWidth){
                     ImgD.width=FitWidth;
                     ImgD.height=(image.height*FitWidth)/image.width;
                 }else{
                     ImgD.width=image.width; 
                    ImgD.height=image.height;
                 }
             } else{
                 if(image.height>FitHeight){
                     ImgD.height=FitHeight;
                     ImgD.width=(image.width*FitHeight)/image.height;
                 }else{
                     ImgD.width=image.width; 
                    ImgD.height=image.height;
                 } 
            }
         }
     }
     </script>