控制图片按比例显示(1)

CS代码:

///


  /// 宽度
  ///
  
  public int GetWidth(string url)
  {
   string urrl = Server.MapPath("../cmall") + url;
   double k;
   double width=0;
   double height=0;
   System.Drawing.Bitmap  imgObj = new Bitmap(urrl);   
   if ((imgObj.Width != 0) && (imgObj.Height != 0))
   {
    width=imgObj.Width;
    height=imgObj.Height;
    k=Convert.ToDouble( width/height); 
    
    if(k>=1)
    {
     if (width>=80)
     {
      width=80;
      height=width/k;
     }
    }
    else
    {
     if (height>=80)
     {
      height=80;
      width=k*height;
     }
    }
   }
   int wid = Convert.ToInt32(width);

   return wid;
  }

  ///


  /// 高度
  ///
  
  public int GetHeight(string url)
  {
   string urrl = Server.MapPath("../cmall") + url;
   double k;
   double width=0;
   double height=0;
   System.Drawing.Bitmap  imgObj = new Bitmap(urrl);   
   if ((imgObj.Width != 0) && (imgObj.Height != 0))
   {
    width=imgObj.Width;
    height=imgObj.Height;
    k=Convert.ToDouble( width/height);
    
    if(k>=1)
    {
     if (width>=80)
     {
      width=80;
      height=width/k;
     }
    }
    else
    {
     if (height>=80)
     {
      height=80;
      width=k*height;
     }
    }
   }
   int hid = Convert.ToInt32(height);
   return hid;
  }

 

HTML代码:


                           

你可能感兴趣的:(ASP.NET)