aspect ratio RRS feed

  • Question

  • User52920949 posted
    I am trying to display some images from my HDD in an aspx page. As most of the images are quite large, I want to reduce their size so that I can view several at once. I want to reduce the height to some predfined number, say 150px. And, in order to keep the aspect ratio, I need to know what the original dimensions were - new width = 150/original height x original width The problem is that I can't seem to get the original dimensions from the image object - <%@ Page Language="VB" debug="true" %> <script runat="server"> Sub Page_Load() Dim imageFile As New System.Web.UI.WebControls.Image() imageFile.ImageUrl = "someimage.JPG" Page.Controls.Add(ImageFile) myLabel.Text = "Width = " & imageFile.Width.ToString() & ", Height = " & imageFile.Height.ToString() end sub </script> <title>Thumbnail</title> <form runat="server"> <asp:label id="myLabel" runat="server" />
    All I get is "Width = , Height = " Can someone help? Thanks Martin
    Wednesday, October 6, 2004 2:01 AM

All replies

  • User-1372641848 posted
    You can not use System.Web.UI.WebControls.Image to get image width or height. more about System.Web.UI.WebControls.Image You will need to use System.Drawing.Image to resize or get width or height of image file. more about System.Drawing.Image
    Thursday, October 7, 2004 11:01 AM
  • User-248717699 posted
    Try this Dim img as System.Drawing.Image img = System.Drawing.Image.FromFile("c:\myimage.jpg") Response.Write(img.Width.ToString() & " x " & img.Height.ToString())
    Friday, October 8, 2004 12:39 PM