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

CS代码:

/// <summary>
  /// 宽度
  /// </summary>  
  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;
  }

  /// <summary>
  /// 高度
  /// </summary>  
  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:Image id=Image2 runat="server" Width='<%# GetWidth(DataBinder.Eval(Container.DataItem, "BigImageURL").ToString())%>' ImageUrl='<%# "../CMALL"+ DataBinder.Eval(Container.DataItem, "BigImageURL") %>' BorderWidth="1px" Height='<%# GetHeight(DataBinder.Eval(Container.DataItem, "BigImageURL").ToString())%>' BorderStyle="Solid" BorderColor="Gray" ToolTip="查看详细信息">
                           </asp:Image>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值