這二天想了想決定把自己先前做的項目中的小的功能,整理一下,奉獻大家!經大家提議,我決定加上源代碼,但是源代碼不一定都是我寫的,有的來自書上,有的來自網上,有的來自開源項目,與我自己的代碼有不相符的,那就是先前的例子!
源代碼:smallImg.rar
以下是上傳一張800*1000的,分別生成不同縮略圖
命名空間:
using System.IO;
核心代碼:
System.Drawing.Image.GetThumbnailImageAbort callb = null;
try
{
// 保存到指定的文件夾
File1.PostedFile.SaveAs(Server.MapPath("/semir/ImgSides/") + sidePath);
MyImage = System.Drawing.Image.FromFile(Server.MapPath("/semir/ImgSides/") + sidePath);
// 保存大圖(原圖)
NewImage = MyImage.GetThumbnailImage(800, 1000, callb, new System.IntPtr());
NewImage.Save(Server.MapPath("/semir/ImgSides/") + "big" + sidePath);
// 保存中圖
NewImage = MyImage.GetThumbnailImage(400, 500, callb, new System.IntPtr());
NewImage.Save(Server.MapPath("/semir/ImgSides/") + "middle" + sidePath);
// 單款衣服的圖片大小
NewImage = MyImage.GetThumbnailImage(255, 319, callb, new System.IntPtr());
NewImage.Save(Server.MapPath("/semir/ImgSides/") + "SingleImage" + sidePath);
// 保存小圖
NewImage = MyImage.GetThumbnailImage(115, 144, callb, new System.IntPtr());
NewImage.Save(Server.MapPath("/semir/ImgSides/") + "small" + sidePath);
// 保存極小圖
NewImage = MyImage.GetThumbnailImage(45, 56, callb, new System.IntPtr());
NewImage.Save(Server.MapPath("/semir/ImgSides/") + "dinky" + sidePath);
MyImage.Dispose();
NewImage.Dispose();
// 一定要釋放,否則進程被占用
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
http://skylaugh.cnblogs.com/archive/2006/06/27/436908.Html