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>