这二天想了想决定把自己先前做的项目中的小的功能,整理一下,奉献大家!经大家提议,我决定加上源代码,但是源代码不一定都是我写的,有的来自书上,有的来自网上,有的来自开源项目,与我自己的代码有不相符的,那就是先前的例子!
源代码: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