﻿



function DrawImage(ImgD,iwidth,iheight){
    DrawImageWithTitle(ImgD,iwidth,iheight,false);
  }


function DrawImageWithTitle(ImgD,iwidth,iheight,showToolTip){
	var ori=ImgD.style.display;
    ImgD.style.display='none';   
    //alert(iwidth+" "+iheight);
    if(!ImgD) return;
    var image=new Image();
    image.src=ImgD.src;
    var neww,newh;
    if(image.width>0 && image.height>0){
    //flag=true;
    if(image.width/image.height>= iwidth/iheight){
        if(image.width>iwidth){  
        neww=ImgD.width=iwidth;
        newh=ImgD.height=(image.height*iwidth)/image.width;
        }else{
        neww=ImgD.width=image.width;  
        newh=ImgD.height=image.height;
        }
        if(showToolTip){
        ImgD.alt="原图("+image.width+"x"+image.height+")建议("+iwidth+"x"+iheight+")根据建议缩放为("+neww+"x"+parseInt(newh)+")";
        }
        }
    else{
        if(image.height>iheight){  
        newh=ImgD.height=iheight;
        neww=ImgD.width=(image.width*iheight)/image.height;  
        }else{
        neww=ImgD.width=image.width;  
        newh=ImgD.height=image.height;
        }
        if(showToolTip){
        //ImgD.alt=image.width+"x"+image.height;
         ImgD.alt="原图("+image.width+"x"+image.height+")建议("+iwidth+"x"+iheight+")根据建议缩放为("+parseInt(neww)+"x"+newh+")";
        }
        }
    }
	ImgD.style.display=ori;   
} 


