FitMesh-like function for images?

BlitzMax Forums/BlitzMax Programming/FitMesh-like function for images?

flying willy(Posted 2005) [#1]
Hi there,

I'd like to load a bunch of images for my tile editor but they are all different sizes. Some are 128x128, some are 64x128 and so on.

What I would love to do is scale them all to 64xAspect

So that they are all the same width, and the height is scaled in proportion to the width (so that they are not warped).

This will allow them to fit into the tile browser really nicely, which is limited by width but not height.

I really appreciate any tips on finding the right SetScale sizes... Thanks lads!


TeaVirus(Posted 2005) [#2]
Something like this? (untested)

local a:float=64.0/tile.width
SetScale tile.width*a,tile.height/a


flying willy(Posted 2005) [#3]
hmmm nope... I wonder if it's something to do with the fact it doesn't accept scale values but something else.


teamonkey(Posted 2005) [#4]
local a:float=64.0/Float(tile.width)
SetScale Float(tile.width)*a,Float(tile.height)/a 

?


ImaginaryHuman(Posted 2005) [#5]
How about something like...

(for each tile)

tile.scaling=tile.width/64 - ie to make all the widths 64
tile.newwidth=tile.width/tile.scaling
tile.newheight=tile.height/tile.scaling

It's up to you whether you think you would need to use floats for the division - if you are using sizes in powers of 2 (ie 32,64,128,256 etc) then integers should be fine.


TeaVirus(Posted 2005) [#6]
Whoops sorry... Wasn't thinking. This works:

SetScale 64.0/img.width,64.0/img.width


flying willy(Posted 2005) [#7]
Are you sure these work? SetScale doesn't use the actual image's scale - it starts at 1,1


TeaVirus(Posted 2005) [#8]
Yes, that will pass the scale value based on the width of the tile to SetScale.