Get Image dimentions from reading graphic files

BlitzMax Forums/BlitzMax Programming/Get Image dimentions from reading graphic files

Dibble(Posted 2010) [#1]
Hi There
I am coding an animation of clouds moving across a sky on several planes
all of them have different x and y sizes.

I was wondering is there a way of finding out graphic dimentions from a bitmap or any graphic file with only one frame.

It would save me having to manualy look at each one in turn and then type them in one by one. As I need this information for sprite
placement.

Doesnt matter if it can't be done and sorry for a daft question if
thats the case.

Thanks
Dibble


Perturbatio(Posted 2010) [#2]
if the graphic has only one frame, then you can load it as a pixmap and use pixmapwidth to get it's dimensions.


Czar Flavius(Posted 2010) [#3]
There is also ImageWidth/Height functions for TImage.


Jesse(Posted 2010) [#4]
you can also use:
myImage.width
and:
myImage.height
myImage refers to what ever name you use for the image.


Czar Flavius(Posted 2010) [#5]
Use of a ruler on the screen is also an established technique!


GfK(Posted 2010) [#6]
BlitzSupport wrote some code to do this which didn't require pre-loading of the image. Check the code archives.


Dibble(Posted 2010) [#7]
Very useful, will save me a lot of time
Many Thanks


Dibble(Posted 2010) [#8]
Here is a program I wrote today from your help

'Gets a list of bitmap files with dimensions
'to get a list of dimensions from one framed bitmapped files named:
'cloud1 to cloud14

Strict

Local the_image:TImage 'the current image to check dimensions on
Local l_count 'for looping through all the image files
Local the_filename:String 'gets the path and then adds the file name then adds the extension
Local load_filename:String 'gets the fliename and file extention

'path to my games directory
Const path:String = "/Bubble Bobble BB/Graphics/Level/Clouds/"
Const filename:String = "Cloud" 'the part of image file which doesnt change

Const From_Num = 1 'part of the image name start number eg cloud1
Const To_Num = 14 'to this number image eg cloud14

Print "File name W H"
Print "----------------------"

For l_count = From_Num To To_Num

the_filename = filename + l_count + ".bmp"
load_filename = path + the_filename
the_image = LoadImage (load_filename) 'load in the image to check
'Error checking dont access the_image object if null
If the_image <> Null
Print the_filename + " " + the_image.width +" " + the_image.height 'print the file information to screen
Else
Print "unable to load:"+the_filename
End If
Next

Rem
Sample output

File name W H
----------------------
Cloud1.bmp 80 22
Cloud2.bmp 51 21
Cloud3.bmp 71 19
Cloud4.bmp 50 21
...
Cloud14.bmp 53 17

End Rem