源代碼: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());
}