determine the pixel resolution of an image file

Discussion in 'ASP .Net' started by Bruce, May 22, 2006.

  1. Bruce

    Bruce Guest

    I have an asp.net page that is dynamically building a table and populating
    cells with images (typically jpeg) and with associated metadata.

    How can the asp.net code efficiently determine the pixel resolution from the
    image file (without loading the entire image into memory on the server) to
    allow it to properly size the table cell and its associated Image control?

    Thanks, Bruce
    Bruce, May 22, 2006
    #1
    1. Advertising

  2. Bruce wrote:
    > I have an asp.net page that is dynamically building a table and populating
    > cells with images (typically jpeg) and with associated metadata.
    >
    > How can the asp.net code efficiently determine the pixel resolution from the
    > image file (without loading the entire image into memory on the server) to
    > allow it to properly size the table cell and its associated Image control?
    >
    > Thanks, Bruce
    >
    >


    Hi Bruce,
    As u have written "image file (without loading the entire image
    into memory on the server)" may not be feasible without loading the
    image into memory. Because to access the properties of the particular
    Image, need to first create an object of the image and then u can access
    the properties of that image. And creating an object will always consume
    the memory for the object.

    Regards,
    Sandy
    Sandeep Singh, May 22, 2006
    #2
    1. Advertising

  3. Hi Bruce,

    Thank you for posting!

    I think you can use GDI+ to read the metadata from the image file. Here's a
    sample:

    # Discovering the properties of an image
    http://www.bobpowell.net/discoverproperties.htm

    Hope this helps.

    Regards,
    Walter Wang
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], May 22, 2006
    #3
  4. Bruce

    Bruce Guest

    Walter,

    Thanks for update.

    In the example you referenced, he makes this call:
    Image img = Image.FromFile(dlg.FileName);

    Thus I assume that the entire image file was loaded into memory to prepare
    to query the Image object for properties. My question is whether there is
    any way to get access to the pixel resulution of the file without loading
    the file into memory. (My reason for asking is that it is my understanding
    the JPEG files have metadata within the file that can be extracted without
    loading the entire file. I dont know if this is true for gif, png, etc.)

    According to the earlier post from Sandeep, it sound like the answer is
    likely "no". But if anyone else has ideas, I'd appreciate them.

    Thanks,
    Bruce

    "Walter Wang [MSFT]" <> wrote in message
    news:...
    > Hi Bruce,
    >
    > Thank you for posting!
    >
    > I think you can use GDI+ to read the metadata from the image file. Here's
    > a
    > sample:
    >
    > # Discovering the properties of an image
    > http://www.bobpowell.net/discoverproperties.htm
    >
    > Hope this helps.
    >
    > Regards,
    > Walter Wang
    > Microsoft Online Community Support
    >
    > ==================================================
    > When responding to posts, please "Reply to Group" via your newsreader so
    > that others may learn and benefit from your issue.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    Bruce, May 22, 2006
    #4
  5. Hi Bruce,

    Thank you for your update.

    Yes, you are correct here that GDI+ will load the entire image, since you
    need to create the object before you can query its properties.

    For JPEG file types, if you know that the files are formatted (which is
    publicly documented, but the specification is not owned by Microsoft), you
    should be able to read the image dimension information from the file
    without having to read in the entire file.

    Another thought on this issue would be: since image files normally don't
    change frequently, you might be able to save their dimension information
    separately. Thus only needing to load the image files once.

    Hope this helps.

    Regards,
    Walter Wang
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], May 24, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew FPGA
    Replies:
    0
    Views:
    942
    Andrew FPGA
    Sep 26, 2005
  2. Peter the Swede

    Pixel colorvalue in an Image

    Peter the Swede, Nov 11, 2003, in forum: Java
    Replies:
    3
    Views:
    1,692
    Peter the Swede
    Nov 11, 2003
  3. rfractal30
    Replies:
    5
    Views:
    6,902
    rfractal30
    Mar 6, 2005
  4. cppaddict
    Replies:
    5
    Views:
    392
    Thomas Lempa
    May 24, 2004
  5. André Wagner

    Fastest pixel by pixel operation

    André Wagner, Mar 17, 2008, in forum: Java
    Replies:
    12
    Views:
    1,017
    Larry A Barowski
    Mar 19, 2008
Loading...

Share This Page