Agreed. Many graphics packages play this trick.
However, I don't know of any way to do that using pure .NET, without
resorting to binary reads of the file, etc.
It's certainly possible to read this information from the tag structure of a JPEG file without parsing and decompressing
the entire image but as you say you will need to use a binary reader to get at it. There's a class on my site that does
just this but it's written in VB6 - May be useful as a starting point though.
I have the same problem with TIF files: I want just the dimensions,
but have to read the entire file into an Image object in order to get
them. It would be nice to have a method that would get me the
dimensions in the quickest, most efficient way possible.
TIFF images are also pretty easy to get document size information out of, avoiding for the moment multi-page TIFFs,
which are slightly more complex but still reasonably easily parsable. The only potentially nasty there is that the
format can be written either little of big endian, so you need to wrap calls to the binary stream to potentially flip
the data if the byte order is reversed.
Have a look over on
www.wotsit.org for the format specification, you just need to parse the IFD structure at the start
of the file so you can ignore the vast majority of the document.
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
E-Mail: (e-mail address removed)
WWW:
Http://EDais.mvps.org/