看看以下资料:
//检查上传文件的格式是否有效
if(this.FileUpload1.PostedFile.ContentType.ToLower().IndexOf("image") < 0)
{
Response.Write("上传图片格式无效!");
return;
}
//生成原图
Byte[] oFileByte = new byte[this.FileUpload1.PostedFile.ContentLength];
System.IO.Stream oStream = this.FileUpload1.PostedFile.InputStream;
System.Drawing.Image oImage = System.Drawing.Image.FromStream(oStream);
int oWidth = oImage.Width; //原图宽度
int oHeight = oImage.Height; //原图高度
int tWidth = 100; //设置缩略图初始宽度
int tHeight = 100; //设置缩略图初始高度
//按比例计算出缩略图的宽度和高度
if(oWidth >= oHeight)
{
tHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(tWidth)
/ Convert.ToDouble(oWidth)));
}
else
{
tWidth = (int)Math.Floor(Convert.ToDouble(oWidth) * (Convert.ToDouble(tHeight)
/ Convert.ToDouble(oHeight)));
}
string virtualFilePath = "~//" + CAppConfiguration.Current.BbsUploadFilePath;
是获取上传的图片路径的
this.hfLastUploadImage.Value = filename;
是给控件赋值 路径
string root = CGlobals.GetHttpRoot(this);
获得类型
建议你用断点进去看看
这都是人家自己写的方法,人家只是给你提供一种思路不是源码照搬的!