您的位置:首页 > 其它

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

2006-05-09 15:56 316 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: