How to retrieve image size?

Discussion in 'ASP .Net' started by Leszek, Dec 4, 2003.

  1. Leszek

    Leszek Guest

    Hello,

    I need to set dynamically height and width attributes of an image control on
    a WebForm. I know how to read the whole image from the hard-drive and use
    its height and width properties. I guess it is not efficient as the whole
    image needs to be read. I need to retrieve only two parameters: height and
    width.

    Is it possible to read only the size of image from the hard-drive?

    Thanks,
    Leszek Taratuta
     
    Leszek, Dec 4, 2003
    #1
    1. Advertisements

  2. Leszek,

    You would need to write a component that read the header of the image file.
    If your dealing with large files, many requests, and not a huge server, it
    may be something worthwhile doing.

    OTOH, the client's machine will automatically size the image once
    downloaded, and there isn't a huge overhead in determinging h/w of an image.

    Alex Papadimoulis
     
    Alex Papadimoulis, Dec 4, 2003
    #2
    1. Advertisements

  3. Leszek

    Leszek Guest

    Alex:

    What I am trying to accomplish is to resize the browser window to fit an
    image. I need to retrieve the image size on the server side, so I could
    generate a JavaScript code (window.open ...) providing proper width and
    height of the window.
    Is it difficult to write a code for reading just the image header?
    I would need such code for .jpg, .gif, and .bmp.

    Thanks,
    Leszek Taratuta
     
    Leszek, Dec 4, 2003
    #3
  4. Leszek

    Jaxon Guest

    you'll need to find a copy of the file format spec, then read the files
    header and parse the info.

    I did this a long time ago using VB6 and Gif images.


    Greg Jackson
    PDX, Oregon
     
    Jaxon, Dec 4, 2003
    #4
  5. Leszek

    Leszek Guest

    I have such functions in VBScript and classic ASP. I just thought there
    would be a standard method somewhere using .NET.

    Thanks,
    Leszek
     
    Leszek, Dec 4, 2003
    #5
  6. Hi Leszek,

    Firstly I want to thank Alex and Greg for their great help in this issue. I
    agree with them that we need to write our own functions to do what you need
    in .NET.

    On the other hand, you can send your feedback of our products to Microsoft
    directly.

    Contact Microsoft
    http://register.microsoft.com/mswish/suggestion.asp
    "...
    Microsoft Wish

    Make a product suggestion or feature request. Product enhancement
    suggestions can include:
    Improvements on existing products
    Suggestions for additional features
    Ways to make our products easier to use
    ..."

    I hope it helps.

    Best regards,

    Jacob Yang
    Microsoft Online Partner Support
    Get Secure! ┬ĘC www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jacob Yang [MSFT], Dec 5, 2003
    #6
  7. Leszek

    Lloyd Sheen Guest

    Where do you want to do this? Client or Server. If server then you can use
    the .net classes to get the information. Check out the graphic classes.
    Don't have access to the doc right now but I have done this. It is simple ,
    just create the correct class (the hard part) , one of the constructors
    takes the filename as input. Then there are readable properties to find out
    most of the details of the image.
     
    Lloyd Sheen, Dec 5, 2003
    #7
  8. Here is the way I would do it in VB.Net. I am not sure if this is what you
    mean by reading the whole file or not.

    Dim MyBitmap As New Bitmap(Server.MapPath(".") & "\MyPicture.jpg")
    Me.Label1.Text = "The height is " & MyBitmap.Height.ToString & " and the
    width is " & MyBitmap.Width.ToString
     
    William LaMartin, Dec 5, 2003
    #8
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.