Image sizes

BlitzMax Forums/BlitzMax Beginners Area/Image sizes

MattC(Posted 2004) [#1]
I'm having a bit of a problem with the funky new animation support in my tilemap editor.

How do I get the dimensions of an image without actually loading it? I can't load the images normally because i get an Unhandled Exception: Unable to create texture error on the larger ones. I need to know the dimensions before I can load the image, but I need to load the image before I can read the dimensions!

Catch 22?

It seems the easiest solution would be to include a text file with every anim containing the image size, but that doesn't seem like a very tidy way of doing it...


Shagwana(Posted 2004) [#2]
All image files should have the information your after in the header someplace, just a matter of learning how to parse that information out. So off you go to look up some file specs on the format of the file in question.


EOF(Posted 2004) [#3]
http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=code_66612142003203441&comments=no


MattC(Posted 2004) [#4]
I was starting to feel a bit out of my depth reading about image format headers, but that code Jim posted makes it look easy.

I need a quick fix so just this time, I'll "borrow" code... thanks both


ImaginaryHuman(Posted 2004) [#5]
I would've thought that with Jpeg and other loading support, there would be also some kind of easy implementation of a command to find out information from a picture file.


FlameDuck(Posted 2004) [#6]
Alternatively, you can just catch the exception, and present the user with a suitable errormessage...


MattC(Posted 2004) [#7]
I'm doing somthing like that FlameDuck, if the image doesn't match very specific parameters then it's simply ignored.

The only problem with the source that JimB pointed out, is that the Jpg code in it doesn't seem to work.

The code identifies a jpg by the first two bytes, and assumes that the image dimensions will be found at a set offset from that position. This doesn't seem to be true, which fits with the info I've read about jpg headers.

There's a possibility that my code or my jpg files are wrong, but anyway. BMP is fine for my purposes and the code for BMP works on the files I've tested.