日期:2014-05-18 浏览次数:20525 次
public static void ShowImage(string imageUrl, System.Web.UI.WebControls.Image image1, int width, int height)
{
string Url = imageUrl;
try
{
System.Drawing.Image image = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(Url));
System.Drawing.Size size = new System.Drawing.Size(image.Width, image.Height);
int w = size.Width;
int h = size.Height;
if (w > h)
{
if (w > width)
{
w = width;
h = (w * size.Height) / size.Width;
}
}
else
{
if (h > height)
{
h = height;
w = (h * size.Width) / size.Height;
}
}
image1.Attributes.Add("style", "width:" + w + "px;height:" + h + "px;");
image1.ImageUrl = Url;
}
catch
{
image1.ImageUrl = Url;
}
}
------解决方案--------------------
先正常加载,然后cs里 用楼上的方法,循环缩放。可以吗