all groups > dotnet drawing api > november 2007 >
You're in the

dotnet drawing api

group:

extract image size without reading whole file


Re: extract image size without reading whole file Michael Phillips, Jr.
11/23/2007 12:06:40 PM
dotnet drawing api:
[quoted text, click to view]

There are many image formats. The size of the image when loaded will only
be known after the image has been decoded.

This is especially true for any image that is compressed. Until the decoder
finishes the decompression, there is no way to know the size of the image.


[quoted text, click to view]

extract image size without reading whole file SharpCoderMP
11/23/2007 5:14:54 PM
hi,
i need to know the size of an image without reading the whole file. any
ideas where to start? i assume some p/invoke would be needed :/
i need this because loading whole images into memory takes lots of time.
Re: extract image size without reading whole file Michael Phillips, Jr.
11/24/2007 9:50:07 AM
[quoted text, click to view]

The image decoder reads the signature first, then the headers and finally
the image itself.

The headers will reveal the width and height not the size of the image when
decoded.

Some image formats such as tiff and jpeg allow a thumbnail to be embedded in
the image.

Reading and decoding a thumbnail is much faster than decoding an entire
image.
Displaying a small thumbnail is faster than displaying the full image.

You always have the option to read and decode only the thumbnail, if it is
present in the image.

The shell API's allow the programmer to create and cache thumbnails. Your
code must read and
decode the entire image before a thumbnail can be created. After the
thumbnail is created and cached,
reading and displaying the thumbnail is fast. The thumbnail will be
re-created only when the image has changed
invalidating the thumbnail in the cache.



[quoted text, click to view]

Re: extract image size without reading whole file SharpCoderMP
11/24/2007 12:00:00 PM
[quoted text, click to view]
what about shell? explorer is pretty quick when it comes to reading
image size (and thumbnail). maybe i could use some of the shell32
features? i've seen great thumbnail image extractor (using shell) on
vbaccelerator. i thought that there would be some way to use the same
technique to obtain only image size. unfortunately my knowledge is
Re: extract image size without reading whole file Michael Phillips, Jr.
11/24/2007 12:40:00 PM
[quoted text, click to view]

The shell thumbnail extractor interface passes the required width and height
of the requested thumbnail.

You create a thumbnail to match the width and height passed to you.

Unfortunately, all of the imaging API's require that the image be read,
decompressed and loaded into memory before
the width and height will be known.

You can write your own code to read and parse the image headers to get the
width and height of the image.
This can be down by loading your image files as MemoryStreams. You can make
all of the decisions as what to do next
after parsing the image headers. Simply rewind the stream to position 0 and
pass the memory stream to any of the System.Drawing
loading methods that require a stream.

This website will give you the info needed to read and parse the image
headers of your choice:
http://www.wotsit.org/


[quoted text, click to view]

Re: extract image size without reading whole file SharpCoderMP
11/24/2007 5:55:04 PM
[quoted text, click to view]
now i'm confused. or maybe my original post was confusing :/ the data i
need is in fact image's width and height. so the question is can it or
AddThis Social Bookmark Button