Image Size Determination

  • Thread starter Thread starter Thom Little
  • Start date Start date
T

Thom Little

I would like to dynamically add a .jpg image of arbitrary size to an .aspx
page and reserve the space for the image before it is loaded. Loading the
image is no problem. How can I determine the height and width of the image
before it is loaded? Is there an article that you can point me to on the
subject?
 
Thom,

In order to do this, you will have to load the image on the server side.
Once you do that, you can place the height and width properties in the IMG
tag, which will (I think) cause the browser to reserve space for that image
before it is downloaded (since it knows the dimensions already).

Hope this helps.
 
Thank you.

With some help I was able to come up with the following ...

private void Page_Load(object sender, System.EventArgs e)
{
imgTest2.ImageUrl = @"d:\Client\tlacsharp\private\3\large\01.jpg" ;
Bitmap myBitmap = new Bitmap( imgTest2.ImageUrl );
txtTest2.Text = myBitmap.Height + " x " + myBitmap.Width ;
}
... where there is simply a Text Box for reporting and an image with no
dimensions specified.

The reason I want this is because I want to cycle through all the images in
a directory and find the dimensions of the largest one. I can then reserve
space for the largest one on the page and cycle all the images through that
reserved space.

--
-- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd.
--

Nicholas Paldino said:
Thom,

In order to do this, you will have to load the image on the server side.
Once you do that, you can place the height and width properties in the IMG
tag, which will (I think) cause the browser to reserve space for that image
before it is downloaded (since it knows the dimensions already).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thom Little said:
I would like to dynamically add a .jpg image of arbitrary size to an ..aspx
page and reserve the space for the image before it is loaded. Loading the
image is no problem. How can I determine the height and width of the image
before it is loaded? Is there an article that you can point me to on the
subject?
 
Back
Top