日期:2014-05-20  浏览次数:20638 次

图片自动调整大小的问题
我用一段儿   javascript   在图片载入时自动调整图片的大小,但是如果是一个大图片(面积,呵呵)   图片会在屏幕上先显示原始大小(闪一下),才会缩小到我想要的尺寸

javascript   代码
//图片按比例缩放
var   flag=false;
function   DrawImage(ImgD,iwidth,iheight){
        //参数(图片,允许的宽度,允许的高度)
        var   image=new   Image();
        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;
                }        
                }
        }
        ImgD.alt= "点击查看图片实际大小 "
}  


aspx   中   image   控件

<asp:image   id= "Imgproduct "   runat= "server "   AlternateText= "点击查看实际尺寸 "> </asp:image>

page_load()   中调用   javascript   语句
    Imgproduct.Attributes.Add( "onload ",   "DrawImage(this,250,250) ")//在图片载入时调用   DrawImage()

大家看看有什么办法可以解决这个问题,能提供其他图片自动调整方法的也行



------解决方案--------------------
速度快就看不到吧 哈
不知道

------解决方案--------------------
<script>
function DrawImage(ImgD,iwidth,iheight){
if(ImgD.width> iwidth) ImgD.width = iwidth
if(ImgD.height> iheight) ImgD.height = iheight
ImgD.alt= "点击查看图片实际大小 "
}
</script>