环境经济学研究生:asp.net中队图片的处理

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/27 22:40:35
上传一个图片时怎么把这个图片改变大小以后存起来?asp.net-c#环境.

我写的代码:

public bool f_GenThumbFile(string szFileFullPath, string szFileName, ref string szFileAttribs )
{
try
{
System.Drawing.Image objImage; // = new System.Drawing.Image(
objImage = System.Drawing.Image.FromFile(szFileFullPath + szFileName);

int orgWidth = objImage.Width;
int orgHeight = objImage.Height;

int newWidth;
int newHeight;

szFileAttribs = orgWidth.ToString() + ";" + orgHeight.ToString();

if( orgWidth > orgHeight )
{
newWidth = ThumbImageMaxSize;
newHeight = (orgHeight * newWidth)/orgWidth;
}
else
{
newHeight = ThumbImageMaxSize;
newWidth = (orgWidth * newHeight)/orgHeight;
}

Response.Write(" <br>" + newWidth + " " + newHeight);

System.Drawing.Image objNewImage;
System.Drawing.Image.GetThumbnailImageAbort callBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
objNewImage = objImage.GetThumbnailImage(newWidth, newHeight, callBack, IntPtr.Zero);
objNewImage.Save(Server.MapPath(this.ApplicationPath + ThumbImagePath) + "\\" + szFileName, System.Drawing.Imaging.ImageFormat.Jpeg );
objNewImage.Dispose();

TraceWrite("保存缩略图文件到:" + Server.MapPath(this.ApplicationPath + ThumbImagePath) + "\\" + szFileName);
return true;
}
catch(Exception E)
{
Response.Write(E.Message);
return false;

}
}
public bool ThumbnailCallback()
{
return false;
}