62,050
社区成员
发帖
与我相关
我的任务
分享
function DrawImage(ImgD,iwidth,iheight)//a为图片显示的宽度 b为图片显示的高度
{
var image=new Image();
if(!iwidth)iwidth = iwidth;
if(!iheight)iheight = iheight; //定义允许高度,当宽度大于这个值时等比例缩小
image.src=ImgD.src;
if(image.width>0 && image.height>0)
{
flag=true;
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;
}
}
}
}