复制代码 代码如下: <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> 调用方法: 复制代码 代码如下: