日期:2011-05-29  浏览次数:20398 次

private void ShowThumbnail(string oldfile, string newfile, int h, int w)
  {
   
   System.Drawing.Image img = System.Drawing.Image.FromFile(oldfile);
   System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);

   int oldh = img.Height;
   int oldw = img.Width;

   int newh,neww;

   double h1 = oldh*1.0/h;
   double w1 = oldw*1.0/w;

   double f = (h1>w1)? h1:w1;

   if(f < 1.0)
   {
    newh = oldh;
    neww = oldw;
   }
   else
   {
    newh = (int)(oldh/f);
    neww = (int)(oldw/f);
   }

   System.Drawing.Image myThumbnail = img.GetThumbnailImage(neww, newh, myCallback, IntPtr.Zero);

   myThumbnail.Save(newfile, System.Drawing.Imaging.ImageFormat.Jpeg);

   img.Dispose();
   myThumbnail.Dispose();
  }
  private bool ThumbnailCallback()
  {
   return false;
  }