复制代 代码如下: <br>function DrawImage(ImgD,FitWidth,FitHeight){ <br> var image=new Image(); <br> image.src=ImgD.src; <br> if(image.width>0 && image.height>0){ <br> if(image.width/image.height>= FitWidth/FitHeight){ <br> if(image.width>FitWidth){ <br> ImgD.width=FitWidth; <br> ImgD.height=(image.height*FitWidth)/image.width; <br> } <br> else{ <br> ImgD.width=image.width; <br> ImgD.height=image.height; <br> } <br> } <br> else{ <br> if(image.height>FitHeight){ <br> ImgD.height=FitHeight; <br> ImgD.width=(image.width*FitHeight)/image.height; <br> } <br> else{ <br> ImgD.width=image.width; <br> ImgD.height=image.height; <br> } <br> } <br> } <br>} <p> 调用方法: 复制代码代码如下: