string fullFileName=this.File1.PostedFile.FileName;
string FileName=fullFileName.Substring(fullFileName.LastIndexOf("\\")+1);
string type=fullFileName.Substring(fullFileName.LastIndexOf(".")+1);
if(type=="JPG"||type=="bmp"||type=="gif")
{
this.File1.PostedFile.SaveAs(Server.MapPath("up")+"\\"+FileName);
this.Image1.ImageUrl="up/"+FileName;
}
else
{
Response.Write("<script language='javascript'>alert('不识别的图像格式!');</script>");
}这样上传照片后。照片的比例就变为 提供的image控件的长宽比例了,不好看。怎么才能让照片保持原始比例大小? 求助!!3Q

解决方案 »

  1.   

    应该不可能吧。是否你在前台展示图片的时候设置了image的宽高?
      

  2.   

    只是显示的时候大小成了image的宽高,实际图片大小是不变的,你可以在上传文件里面打开看看
      

  3.   

    看看别人问过:
    http://topic.csdn.net/u/20071229/15/503e0dd9-7292-4fdb-925c-01c60bc095c3.html
    解决办法:
    http://download.csdn.net/source/321082
      

  4.   

    这个一般在客户端用js控制图片按比例缩放(照片保持原始会撑大页面)://JS按比例缩放图片
    function SetSize(img, width, height) 

    var vWidth=img.width;
    var vHeight=img.height;
    img.width=0;
    img.height=0;
    if(vWidth>vHeight){
    img.width=width;
    img.height=vHeight/vWidth*width;
    img.style.marginTop=(height-img.height)/2;
    }else if(vWidth<vHeight){
    img.height=height;
    img.width=vWidth/vHeight*height;
    img.style.marginTop=0;
    }else{
    img.width=width;
    img.height=height;
    img.style.marginTop=0;
    }
    }<img src='http://Img.hengzhe.com/sj/test.jpg' onload='SetSize(this, 100, 100)'  border=0  />
      

  5.   

    可以,你在显示的时候,只指定image控件的长度,或者只指定它的高度,这样就可以了。
      

  6.   

    判断图片长宽比例,如比你的image大,则只指定长度,如小,则只指定宽度 。
      

  7.   


    这个不错 。不过有个缺点就是  图片大小不变 
    其实可以考虑 上传的图片时候生成一个略缩图
    gdi+ 应该可以搞定的的 
      

  8.   

    function SetSize(img, width, height) 

        var vWidth=img.width;
        var vHeight=img.height;
        img.width=0;
        img.height=0;
        if(vWidth>vHeight){
            img.width=width;
            img.height=vHeight/vWidth*width;
            img.style.marginTop=(height-img.height)/2;
        }else if(vWidth<vHeight){
            img.height=height;
            img.width=vWidth/vHeight*height;
            img.style.marginTop=0;
        }else{
            img.width=width;
            img.height=height;
            img.style.marginTop=0;
        }
    }<img src='http://Img.hengzhe.com/sj/test.jpg' onload='SetSize(this, 100, 100)'  border=0  />看不大懂。。里面的img 是指image控件 还是 上传的图片?
    还有if(vWidth>vHeight){
            img.width=width;
            img.height=vHeight/vWidth*width;
            img.style.marginTop=(height-img.height)/2;
        }else if(vWidth<vHeight){
            img.height=height;
            img.width=vWidth/vHeight*height;
            img.style.marginTop=0;
        }else{
            img.width=width;
            img.height=height;
            img.style.marginTop=0;
        }
    这些代码可以给稍微加点注释么?   就是为了保持比例的?
    谢谢大家!!!
      

  9.   

    还有function SetSize(img, width, height)
    这里的width跟 heigt 是什么?
      

  10.   

    还有 function SetSize(img, width, height)
    里面的img width height 各是什么?
     研究ing....
      

  11.   

    有点头绪啦!
    我做的是 asp.net   c#    web应用程序项目
    用在我的程序里么