1

我想在这里使用这个问题的答案:Resize image ratioly with MaxHeight and MaxWidth constraints

但我的图像是 .Net 图像。我想知道是否有任何方法可以使用 .Net 图像的 maxheight 和 maxwidth 约束按比例调整图像大小。这是 asp 代码的样子:

<asp:Image ID="Image1" runat="server" Height="445px" Visible="False" Width="640px" />

后面的代码如下所示:

Image1.ImageUrl = "/Images/" + image1Link.ToString();
4

2 回答 2

1

asp.Net Image 具有与 Winforms Image 相同的属性。您仍然可以使用 Image1.Height 和 Image1.Width。只需将高度和宽度设置为这些属性。检查一个例子:

protected void Page_Load(System.Object sender, System.EventArgs e) {
    if (!Page.IsPostBack) {
        LoadImage();
    }
}

private void LoadImage(){
    Image1.ImageUrl = LoadURLFromDatabase(params);
    Image1.Width = (int)(image.Width * ratio);
    Image1.Height = (int)(image.Height * ratio);
}
于 2013-09-05T14:27:00.153 回答
0

如果我正确理解您的问题,您正在尝试在网页上显示图像。为什么不使用CSS 或将 side 设置为 100%?

<asp:Image ID="Image1" runat="server" Height="445px" Visible="False" Width="100%" />

您也可以尝试“自动”设置。

于 2013-09-05T14:00:48.590 回答