/// <summary>
/// 显示图片
/// </summary>
/// <param name="image"></param>
void ShowImage(string image, int max)
{
string str = Server.MapPath("~/productimages/" + image);
System.Drawing.Bitmap bit = new Bitmap(str);
double bili = Convert.ToDouble(bit.Height) / Convert.ToDouble(bit.Width);
if (bit.Width > bit.Height)
{
if (bit.Width < max)
{
this.Image1.Width = bit.Width;
this.Image1.Height = bit.Height;
}
else
{
int height = Convert.ToInt32((bili * max));
this.Image1.Width = max;
this.Image1.Height = height;
}
}
else
{
if (bit.Height < max)
{
this.Image1.Width = bit.Width;
this.Image1.Height = bit.Height;
}
else
{
int width = Convert.ToInt32(((1 / bili) * max));
this.Image1.Width = width;
this.Image1.Height = max;
}
}
Image1.ImageUrl = "~/productimages/" + image;
}
本文介绍了一种根据图片原始尺寸及最大显示宽度调整图片显示大小的方法。通过计算比例并根据图片宽高比较进行等比例缩放,确保图片在不同场景下的适配性和视觉效果。
2109

被折叠的 条评论
为什么被折叠?



