Picture's width and height

BlitzMax Forums/BlitzMax Programming/Picture's width and height

KamaShin(Posted 2005) [#1]
Is there a way to know a picture's width and height without opening it first and relying on the Width and Height methods???

for instance I m planning on loading a serie of tiles, stored in one single picture... I know my tiles are 32*32 but I don t know how many tiles there are in my picture... Basically I load the picture, get its width and height properties, calculate then the number of tiles this represent (widht*height/32/32), and I then reload my picture using LoadAnimImage... thus I load my picture twice, which is NOT nice if my tiles collection gets a bit big...

well, don t try to find a solution to the example above, this is just an example... there are many other cases for which I'd need to know a picture's width and height without loading it, so I just want to know if it's doable.

thanks in advance :)


Grey Alien(Posted 2005) [#2]
what are you using bmp or jpg? You could read in the file header instead of the whole and extract it from that, don't ask me how though. Failing that how about storing the sizes in a mini text file and reading that (as if you had a level editor that stored this info for you), I know you have to manually update it, but well, there's not many other options.


Duckstab[o](Posted 2005) [#3]
you could just add the width and height to the file name ie "0640_0320_tileset1.bmp"

Then create a function to get the two sizes from the string

Then Pass this info to a function that will calculate the number of tiles and load the image to a pointer that is passed to a variable of your choice


Grey Alien(Posted 2005) [#4]
that's a good idea.


KamaShin(Posted 2005) [#5]
hmmm reading the width and height in the header might be the best solution actually... I think i m going to look into that... I'll have to find somehow how are bmp,jpg and png headers' coded then...
that's cool :)
by the way if anyone knows where I can find details about the headers of those 3 formats, that would prevent me from losing too much time looking around on the net :)


Bremer(Posted 2005) [#6]
Flameduck did the PNG one, and you can find it here:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1492#comments


Grey Alien(Posted 2005) [#7]
But to read the header you need code to just read a tiny part of the start of the file, hope you can manage that.


FlameDuck(Posted 2005) [#8]
by the way if anyone knows where I can find details about the headers of those 3 formats, that would prevent me from losing too much time looking around on the net :)
wotsit.org is your friend.


KamaShin(Posted 2005) [#9]
cool, thanks :)


Hotcakes(Posted 2005) [#10]
You guys are all crazy. All the header loaders for the image formats are contained in Max code already in the image loader modules. Just steal code from there!


KamaShin(Posted 2005) [#11]
yeah LOL, I also thought about it a few minutes before reading your post lol :)
I'm going to do that :)