﻿function DrawImage(ImgD,FitWidth,FitHeight){
 var image=new Image();
 image.src=ImgD.src;
 if(image.width>0 && image.height>0){
  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;
   }
  }
 }
}
//function DrawImage(ImgD,iwidth,iheight){    
//    //参数(图片,允许的宽度,允许的高度)    
//    var image=new Image();    
//    image.src=ImgD.src;    
//    if(image.width>0 && image.height>0){    
//      if(image.width/image.height>= iwidth/iheight){    
//          if(image.width>iwidth){      
//              ImgD.width=iwidth;    
//              ImgD.height=(image.height*iwidth)/image.width;    
//          }else{    
//              ImgD.width=image.width;      
//              ImgD.height=image.height;    
//          }    
//      }else{    
//          if(image.height>iheight){      
//              ImgD.height=iheight;    
//              ImgD.width=(image.width*iheight)/image.height;            
//          }else{    
//              ImgD.width=image.width;      
//              ImgD.height=image.height;    
//          }    
//      }    
//    }    
//}  
//function AutoResizeImage(objImg,maxWidth,maxHeight){
//var img = new Image();
//img.src = objImg.src;
//var hRatio;
//var wRatio;
//var Ratio = 1;
//var w = img.width;
//var h = img.height;
//wRatio = maxWidth / w;
//hRatio = maxHeight / h;
//if (maxWidth ==0 && maxHeight==0){
//Ratio = 1;
//}else if (maxWidth==0){//
//if (hRatio<1) Ratio = hRatio;
//}else if (maxHeight==0){
//if (wRatio<1) Ratio = wRatio;
//}else if (wRatio<1 || hRatio<1){
//Ratio = (wRatio<=hRatio?wRatio:hRatio);
//}
//if (Ratio<1){
//w = w * Ratio;
//h = h * Ratio;
//}
//objImg.height = h;
//objImg.width = w;
//}

