| 04 |    /// <param name="phyPath">原图片的路径</param>  | 
   | 05 |    /// <param name="width">缩略图宽</param>  | 
   | 06 |    /// <param name="height">缩略图高</param>  | 
   | 07 |    /// <returns></returns>  | 
   | 08 |    publicSystem.Drawing.Image GetThumbnail(System.Drawing.Image image, intwidth, intheight)  | 
    | 10 |        Bitmap bmp = newBitmap(width, height);  | 
    | 12 |        System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp);  | 
    | 14 |        gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;  | 
    | 16 |        gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;  | 
    | 18 |        gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;  | 
    | 20 |        System.Drawing.Rectangle rectDestination = newSystem.Drawing.Rectangle(0, 0, width, height);  | 
    | 22 |        gr.DrawImage(image, rectDestination, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);  | 
         
 调用方法
     | 01 | HttpPostedFile file = photoFile.PostedFile;  | 
   | 02 |         if(!file.ContentType.Contains("image"))  | 
      | 06 |         stringext = Path.GetExtension(file.FileName).ToLower();  | 
   | 07 |         if(ext != ".jpg"&& ext != ".gif"&& ext != ".png"&& ext != ".jpeg")  | 
    | 09 | return"请您上传jpg、gif、png图片";  | 
    | 11 |         if(file.ContentLength > 5 * 1024 * 1024)  | 
      | 15 |         stringnewName = Guid.NewGuid().ToString();  | 
   | 16 |         stringtempPath = "upload/";  | 
   | 17 |         stringimg = tempPath + newName + ext;  | 
   | 18 |         stringfilePath = Server.MapPath(img);  | 
   | 19 |         if(!Directory.Exists(tempPath))  | 
    | 21 |             Directory.CreateDirectory(tempPath);  | 
    | 23 |         using(System.Drawing.Image originalImage = System.Drawing.Image.FromStream(file.InputStream))  | 
    | 25 |             GetThumbnail(originalImage, 504, 374).Save(filePath);  | 
       
  
转载于:https://www.cnblogs.com/gc2013/p/3652469.html