图像缩放的代码相信大家都找得到,不过除了缩放还要保持纵横比的呢?哈哈,看下面的代码吧,它能棒你解决这个问题。
function DrawImage(ImgD,maxSize)
{
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0)
{
if(image.width/image.height>=1)
{
if(image.width>maxSize)
{
ImgD.width=maxSize;
ImgD.height=(image.height*maxSize)/image.width;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else
{
if(image.height>maxSize)
{
ImgD.height=maxSize;
ImgD.width=(image.width*maxSize)/image.height;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}转载请注明出处-中国设计秀-cnwebshow.com