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
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
http://topic.csdn.net/u/20071229/15/503e0dd9-7292-4fdb-925c-01c60bc095c3.html
解决办法:
http://download.csdn.net/source/321082
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 />
这个不错 。不过有个缺点就是 图片大小不变
其实可以考虑 上传的图片时候生成一个略缩图
gdi+ 应该可以搞定的的
{
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;
}
这些代码可以给稍微加点注释么? 就是为了保持比例的?
谢谢大家!!!
这里的width跟 heigt 是什么?
里面的img width height 各是什么?
研究ing....
我做的是 asp.net c# web应用程序项目
用在我的程序里么