设为首页
加入收藏
站内地图
旧版入口
当前位置:首页 > 站长学院 > 网络编程 > ASP.NET

生成图片缩略图

作者:佚名 出处:网络转载 时间:11-07 点击:

内容载入中...
if(System.IO.File.Exists(path))
    {
     goodsid+=dt.Rows[i]["goodsid"].ToString()+",";
//     if(!System.IO.File.Exists(Picpath))
//     {
      System.Drawing.Image img=System.Drawing.Image.FromFile(path);
      //生成中图
     int w=img.Width;  //当前图片的宽
     int h=img.Height;  //当前图片的高
     int x=0;           //设置生成图片的宽
     int y=0;           //设置生成图片的高
    int curx=182;
    int cury=122;
     if(w>=curx && h<=cury)
     {
      x=curx ;
      y=curx *h/w;
     } 
     else if(h>=cury&& w<=curx )
     {
      y=cury;
      x=cury*w/h;
     }
     else if(h>=cury&& w>=curx )
     {
      if(h/cury>w/curx )
      {
       x=curx ;
       y=curx *h/w;
      }
      else
      {
       y=cury;
       x=cury*w/h;
      }
     }
     else if(h<=cury&& w<=curx )
     {
      x=img.Width;
      y=img.Height;
     }
      System.Drawing.Image  newimg=img.GetThumbnailImage(x,y,null,new System.IntPtr(0));
      newimg.Save(Picpath,System.Drawing.Imaging.ImageFormat.Jpeg);
      img.Dispose();
      newimg.Dispose();
收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口

站长学院

推荐信息