控制图片按比例显示(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>
/// <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>
相关文章推荐
- JS控制图片显示的大小(图片等比例缩放)
- JS控制图片显示的大小(图片等比例缩放)
- html关于div控制比例,及控制图片显示形状
- javascript: 改变和控制显示的图片大小(保持比例,同时可限制高宽)
- javascript: 改变和控制显示的图片大小(保持比例,同时可限制高宽)
- JS控制图片显示的大小(图片等比例缩放)
- JS控制图片显示的大小(图片等比例缩放)
- ASP控制图片显示的大小(等比例缩放)
- JS控制图片显示的大小(图片等比例缩放)
- javascript代码控制图片在页面显示时等比例缩放
- JS控制图片显示的大小(图片等比例缩放)
- \t\t用js控制页面图片等比缩放 css图片等比缩放 比例缩放显示 js 页面 缩放图片 js缩放图片 图片按比例缩放
- JS控制图片显示的大小(图片等比例缩放)
- ASP控制图片显示的大小(等比例缩放)
- JS控制图片显示的大小(图片等比例缩放)
- JS控制图片显示的大小(图片等比例缩放)
- JS控制图片显示的大小(图片等比例缩放)
- JS控制图片显示的大小(图片等比例缩放)
- S实现控制图片显示大小的方法【图片等比例缩放功能】
- JS控制图片显示的大小(图片等比例缩放)