function DrawImage(ImgD,FitWidth,FitHeight){
var image=new Image();
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;
}
}
}
}
var image=new Image();
image.src=ImgD.src;
/*
image.width 图片原宽
image.height 图片原高
FiWidth 显示图片区域宽
FitHeight 显示图片区域高
ImgD.width 缩放后图片的宽
ImgD.height 缩放后图片的高
*/
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;
}
}
}
}