determine the pixel resolution of an image file

  • Thread starter Thread starter Bruce
  • Start date Start date
B

Bruce

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 said:
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
 
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,

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
 
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.
 
Back
Top