生成图片的缩略图

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

posted @ 2006-10-18 12:50  '.Elvis.'  阅读(109)  评论(0编辑  收藏  举报