I want to read ICO file and save every icon into separate BMP. My code does the trick for the first icon in ICO files. But then I don't know where to set the file cursor (where to fseek to).
Here's are the steps I do, in pseudocode:
But where do I fseek to now? I tried reading from the place I finished but with no luck. I know the next icon is 48x48 bytes in size, so I think i should read next ICONDIRENTRY which should give me 'width' and 'height' = 48. But I don't know where to start reading from.
I am writing the program in PHP but PHP guys for questions like this usually say 'use library X' or 'use ImageMagick' and I just need to know the algorithm. Such programs are usually written in C++ so I tagged this C++.
Where is the next ICONDIRENTRY in the ICO file (what offset)?
You're nearly there...
The ICO format starts with the ICONDIR, a short header and one or more ICONDIRENTRY blocks that define the parameters for each icon in the file. To read the whole file start by reading the ICONDIR and parsing the ICONDIRENTRY blocks into an array.
Then loop through your array using the offset in each entry to seek to the next image.
The file format is described on MSDN, and there's also an article on Wikipedia