Archived

This topic is now archived and is closed to further replies.

clum

Finding the size of a JPEG file

Recommended Posts

clum    217
I have a JPEG file which I don''t need to actually read. I just need to find the dimensions of the image. Is there a simple location in the file where I should look? All the specifications and code samples I''ve seen for reading JPEGs were really complicated. Thanks. Zorx (a Puzzle Bobble clone) Discontinuity (an animation system for POV-Ray)

Share this post


Link to post
Share on other sites
Mastaba    761
It is really quite simple. The file is divided into sections. Each section generally starts with a 16 bit marker followed by a 16 bit word for the length of that section including that word. The image begins with marker 0xFFD8 and does not have a length following it. Instead you typically have one or more subsections that follow it. Read through the subsections in section 0xFFD8 until you find section 0xFFC0. The image height and width are 16 bit words in that section immediately following the length of that section (actually 1 byte beyond the length word). Also take note that JPEGS are big endian files.



[edited by - Mastaba on March 22, 2004 1:00:46 AM]

Share this post


Link to post
Share on other sites