HighTechTalks DotNet Forums  

extract image size without reading whole file

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss extract image size without reading whole file in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
SharpCoderMP
 
Posts: n/a

Default extract image size without reading whole file - 11-23-2007 , 10:14 AM






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.
and when you have lets say 300 of them, 6Mpix each it may take ages.

Reply With Quote
  #2  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: extract image size without reading whole file - 11-23-2007 , 11:06 AM






Quote:
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.
and when you have lets say 300 of them, 6Mpix each it may take ages.
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.


"SharpCoderMP" <csharp_mp (AT) interia (DOT) pl.NFSPM> wrote

Quote:
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.
and when you have lets say 300 of them, 6Mpix each it may take ages.



Reply With Quote
  #3  
Old   
SharpCoderMP
 
Posts: n/a

Default Re: extract image size without reading whole file - 11-24-2007 , 05:00 AM



Michael Phillips, Jr. wrote:
Quote:
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.
and when you have lets say 300 of them, 6Mpix each it may take ages.

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.
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
rather limited when it comes to shell programming :/


Reply With Quote
  #4  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: extract image size without reading whole file - 11-24-2007 , 08:50 AM



Quote:
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
rather limited when it comes to shell programming :/
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.



"SharpCoderMP" <csharp_mp (AT) interia (DOT) pl.NFSPM> wrote

Quote:
Michael Phillips, Jr. wrote:
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.
and when you have lets say 300 of them, 6Mpix each it may take ages.

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.
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
rather limited when it comes to shell programming :/



Reply With Quote
  #5  
Old   
SharpCoderMP
 
Posts: n/a

Default Re: extract image size without reading whole file - 11-24-2007 , 10:55 AM



Michael Phillips, Jr. wrote:
Quote:
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.
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
can not be done in some fast way (ie using shell32)?


Reply With Quote
  #6  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: extract image size without reading whole file - 11-24-2007 , 11:40 AM



Quote:
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
can not be done in some fast way (ie using shell32)?
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/


"SharpCoderMP" <csharp_mp (AT) interia (DOT) pl.NFSPM> wrote

Quote:
Michael Phillips, Jr. wrote:
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.
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
can not be done in some fast way (ie using shell32)?



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.