﻿
var flag=false;
//参数1 img控件 参数2 框架宽度 参数3 框架高度
function DrawImage(ImgD,www,hhh)
{ 
    var image=new Image(); 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0)
    { 
        flag=true;
        //如果原图的宽高比大于框架的宽高比
        if(image.width/image.height>= www/hhh)
        { 
            if(image.width>www)
            { 
                ImgD.width=www; 
                ImgD.height=(image.height*www)/image.width; 
            }
            else
            { 
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            } 
            //ImgD.alt=image.width+"x"+image.height; 
        }
        //如果原图的宽高比小于框架的宽高比
        else
        { 
            if(image.height>hhh)
            { 
                ImgD.height=hhh; 
                ImgD.width=(image.width*hhh)/image.height; 
            }
            else
            { 
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            } 
            //ImgD.alt=image.width+"x"+image.height; 
        } 
    } 
} 

