所谓制作缩略图就是把一张尺寸很大的图成比例地缩小为一张尺寸较小的图。为了实现这个功能,可以使用.NET Framework提供的一个委托方法System.Drawing.Image.GetThumbnailImageAbort,从而使用Image.GetThumbnailImage生成缩略图。代码如下,非常简单易懂:
1 private void GenThumbnailImage()
2 {
3 System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("Waterlilies.jpg"));
4 System.Drawing.Image.GetThumbnailImageAbort callBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallBack);
5 System.Drawing.Image thumbImage = image.GetThumbnailImage(image.Width/10, image.Height/10, callBack, new System.IntPtr());
6 thumbImage.Save(Server.MapPath("SmallWaterlilies.jpg"));
7 image.Dispose();
8 thumbImage.Dispose();
9 }
10
11 private bool ThumbnailCallBack()
12 {
13 return true;
14 }
2 {
3 System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("Waterlilies.jpg"));
4 System.Drawing.Image.GetThumbnailImageAbort callBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallBack);
5 System.Drawing.Image thumbImage = image.GetThumbnailImage(image.Width/10, image.Height/10, callBack, new System.IntPtr());
6 thumbImage.Save(Server.MapPath("SmallWaterlilies.jpg"));
7 image.Dispose();
8 thumbImage.Dispose();
9 }
10
11 private bool ThumbnailCallBack()
12 {
13 return true;
14 }
来源:http://www.cnblogs.com/sjpisaboy/archive/2006/04/06/368417.html