﻿function DrawImage(ImgD,WidthNum,HeightNum){ 
var image=new Image(); 
image.src=ImgD.src; 
if(image.width>0 && image.height>0){ 
flag=true; 
if(image.width/image.height>= WidthNum/WidthNum){ 
if(image.width>WidthNum){ 
ImgD.width=WidthNum; 
ImgD.height=(image.height*WidthNum)/image.width; 
}else{ 
ImgD.width=image.width; 
ImgD.height=image.height; 
} 

} 
else{ 
if(image.height>HeightNum){ 
ImgD.height=HeightNum; 
ImgD.width=(image.width*HeightNum)/image.height; 
}else{ 
ImgD.width=image.width; 
ImgD.height=image.height; 
} 

} 
} 
} 

<!--    
var flag=false;    
function limitImage(ImgD){    
    var areaWidth = 150;  //你放置图片区域的宽度。   
    var areaHeight = 120; //你放置图片区域的高度。   
    var image=new Image();    
    image.src=ImgD.src;    
    if(image.width>0 && image.height>0){    
        flag=true;    
        if(image.width/image.height>= areaWidth/areaHeight){    
            if(image.width>areaWidth){    
                ImgD.width=areaWidth;    
                ImgD.height=(image.height*areaWidth)/image.width;    
            }else{    
                ImgD.width=image.width;    
                ImgD.height=image.height;    
            }    
            //ImgD.alt=image.width+"×"+image.height;    
        }else{    
            if(image.height>areaHeight){    
                ImgD.height=areaHeight;    
                ImgD.width=(image.width*areaHeight)/image.height;    
            }else{    
                ImgD.width=image.width;    
                ImgD.height=image.height;    
            }    
            //ImgD.alt=image.width+"×"+image.height;    
        }    
    }    
}    
//-->    
