getting image size

K

karimL

Hi,
how can I retrieve the height and width of
a System.Web.UI.WebControls.Image after populating it's ImageUrl property.
It's seems not to be filled ?
Does someone have a solution ?


Thanks
Karim
 
M

Mark Fitzpatrick

You can't. These values aren't available at that time because the image
itself isn't loaded into the form. All it's doing is telling the browser
where to get the image from. The width and height can be set independantly
of the image. For example. you can specify a 100 pixel width for an image
even though it's a 1 pixel spacer. Essentially though, getting the image
value won't do you any good in an Image webcontrol because, since the image
is never really opened server-side, the server doesn't actually know the
size of the image. You would have to open it as a bitmap using some of the
System.Drawing classes to really open the image first in order to find the
size.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
B

Big D

If you need the information you can retrieve it by something like

Dim img As System.Drawing.Image
img = System.Drawing.Image.FromFile("blah.jpg")

myWebControlImage.Width = img.Width
myWebControlImage.Height = img.Height

Hope that helps.

-D
 
K

KarimL

Thanks for your advices...
but i need to get the Image height because i dynamically resize the height
of my webcontrol based
on image height.
More i just have the url (relative parth) to the the image but in design
time mode all variables concerning Server or Context
ar not set ?.... so I can't use MapPath function to obtain the physical
parth of the picture ... then second question is how to obtain the
physical path from relative path in Design Mode...

Thanks
Karim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top