我的图像有 250x250px 的空间。图像保存在服务器上,文件名保存在数据库中。
现在我只设置了 img-src 标签和宽度 = 250 和高度 = 250 - 但是会发生什么情况,它更高然后更亮的图片不会以正确的关系显示,因为我破坏了关系。
那么如何设置正确的宽度和高度,最大为 250px 但在图像的关系范围内?
试试这个:
<div style="height: 250px;width:250px">
<img src="yourimage.jpg" style="max-width: 100%; max-height: 100%;">
</div>
我处理这个:
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
int height = img.Height;
int width = img.Width;
string hwText = "";
if (height > width) //Höher als Breiter
{
hwText = "height='250px'";
}
else //Breiter als Höher
{
hwText = "width='250px'";
}