How do I find out how many frames an image is?

BlitzPlus Forums/BlitzPlus Programming/How do I find out how many frames an image is?

RexRhino(Posted 2003) [#1]
OK, I want to find out how many frames an image is? How would I do this? There appears to be no ImageFrames(image) command or anything like this?


CS_TBL(Posted 2003) [#2]
iirc, you can't, and it sux indeed. If you know the size of a frame, and the size of the whole picture, then you can calculate how many frames there are... you could also store the amounf of frames in the filename.. but anyway.. I suggest an ImageFrames(image) function too ..


BlitzSupport(Posted 2003) [#3]
You have to supply the number of frames during LoadAnimImage; there's no way for Blitz to tell how many frames are in an arbitrary image strip...


Kevin_(Posted 2003) [#4]
Can you not just increase the number of frames in LoadAnimImage until an error appears. That way, you just deduct 1 and you have the number of frames.

Just a thought...

Regards


Synchronist(Posted 2003) [#5]
@RR, you could use an array that uses the image file name as an index to the number of frames it contains. Of course, you would have to know the number before hand... It would be simple to implement as a DATA set I would think. Just an idea. 8^)

The problem I can see with resolving the number of frames "on the fly" is that the program could not know the size of each frame before hand. If an image strip is 20 x 100 pixels, how many different permutations would be possible to describe a frame size? Lots of them...


Hotcakes(Posted 2003) [#6]
In my code I have wrapper functions for loading anim images, which only need the width and height of each frame and a type to store info in. Then I just LoadImage the image first, grab the width and height of the entire thing, divide totalwidth by framewidth and assuming it's an even number of frames, everything is ok. Then I LoadAnimImage it with the determined number of frames. Simple. A bit more elegant than Prof's solution... especially considering Blitz chucks up a nasty error box and quits if there aren't enough frames, instead of returning 0... I think =]


Teddyfles(Posted 2003) [#7]
Basicly like Hotcakes said:
Const frame_w = 40
Const frame_h = 40

tmp = LoadImage("Data/Tileset.bmp")
tileset_max = (ImageWidth(tmp) / frame_w) * (ImageHeight(tmp) / frame_h)
FreeImage tmp

iTileSet = LoadAnimImage("Data/Tileset.bmp", frame_w, frame_h, 0, tileset_max)



uwdesign(Posted 2003) [#8]
I had this problem also. My solution was to read the bitmap files header. The grab the width/height to calc the required number of frames. Then you can loadAnimImage as normal. Avoids having the 2 copies the image in memory a once.


On a related note:

Is there any reason why the LoadAnimImage command doesn't seem allow more than 1024 frames ?..