首页 > 开发 > 综合 > 正文

c#生成缩略图

2024-07-21 02:26:54
字体:
来源:转载
供稿:网友
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;
  }

,欢迎访问网页设计爱好者web开发。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表