CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2000
    Vancouver, BC, Canada

    getting the height of an image

    I'm displaying images using ajax (photo album) and I'm setting the width of the image when I draw it to the form, and leaving the height 'unmentioned'. Normally, this allows the browser to auto-size the height based on the dimensions of the image, based on the specified width. I'm finding the width goes to what I specify it as, but the height does not auto-adjust when I used javascript, and I end up displaying a vertically stretched image the looks terrible.

    anyone know how to get the dimensions of the image so I can adjust the height programmatically? Anyone have any other working methods I haven't thought of?
    David Meikle
    Quantum Unit Solutions, LLC

  2. #2
    Join Date
    Aug 2005
    Milwaukee, WI

    Re: getting the height of an image

    I don't know if it's possible to get the dimensions of an image like that. I think there may be another way though. Put all of those images (unformatted) in a div whose .style.display='none' so it is hidden. Once they are all there, grab the actual dimensions of each one and use a little math to calculate the new width and height and resize the image. When you are finished with that, reset .style.display='block' or whatever else you use to make it visible again.

    Hope that helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.