function DrawImage(ImgD,maxwidth,maxheight)
{
   var image=new Image(); 
   image.src=ImgD.src;  
   if(image.width>0 && image.height>0)
   {   
        if(image.width/image.height>=maxwidth/maxheight) //宽大于长
        {  
             if(image.width>maxwidth)//如果宽度大于最大宽度
             {    
                 ImgD.width=maxwidth;  
                 ImgD.height=(image.height*maxwidth)/image.width;
				 ImgD.style.marginTop=((maxheight-ImgD.height)/2)+'px';  //此时需要设置垂直居中
             }
             else
             {  
                 ImgD.width=image.width;    
                 ImgD.height=image.height;  
				 ImgD.style.marginLeft=((maxwidth-ImgD.width)/2)+'px';
				 ImgD.style.marginTop=((maxheight-ImgD.height)/2)+'px';
             }  
         }  
        else											 //长大于宽
        {  
             if(image.height>=maxheight)
             {    
                 ImgD.height=maxheight;  
                 ImgD.width=(image.width*maxheight)/image.height; 
				 ImgD.style.marginLeft=((maxwidth-ImgD.width)/2)+'px';
             }
             else
             {  
                 ImgD.width=image.width;    
                 ImgD.height=image.height;  
				 ImgD.style.marginLeft=((maxwidth-ImgD.width)/2)+'px';
				 ImgD.style.marginTop=((maxheight-ImgD.height)/2)+'px';
             }  
        }  
    }
}