***函数名 : DrawImage
***函数说明: 图片等比例缩放
***参数 :
sID: 当前img控件ID
iFitWidth: 缩放的宽度
iFitHeight: 缩放的高度
***返回值 : Null
*/
function DrawImage(sID, iFitWidth, iFitHeight) {
var image = new Image();
var imgOBJ = document.getElementById(sID);
image.src = imgOBJ.src;
if (image.width>0 && image.height>0) {
if (image.width/image.height >= iFitWidth/iFitHeight) {
if (image.width > iFitWidth) {
imgOBJ.width = iFitWidth;
imgOBJ.height = iFitWidth/image.width*image.height;
}
else {
imgOBJ.width = image.width;
imgOBJ.height = image.height;
}
}
else {
if (image.height>iFitHeight) {
imgOBJ.width = iFitHeight/image.height*image.width;
imgOBJ.height = iFitHeight;
}
else {
imgOBJ.width = image.width;
imgOBJ.height = image.height;
}
}
}
}
函数调用实例:DrawImage("MyImage", 400, 300);