The getDimensions() function is the useful bit - the rest is really just to demonstrate. Change the values of frameWidth and frameHeight to test.
PS: I've tested the speed of getDimensions() and it can run 10,000 iterations in 2ms.
Strict
Graphics 800,600
SetBlend SOLIDBLEND
Global framex:Int = 100
Global framey:Int = 100
Global frameWidth:Int = 450
Global frameHeight:Int = 150
Global img:TImage = LoadImage("cut1.jpg")
Global width:Float,height:Float
getdimensions()
While Not AppTerminate()
Cls
drawFrame()
DrawImageRect img,framex,framey,width,height
Flip
Wend
End
Function drawFrame()
SetColor 255,0,0
DrawRect framex,framey,framewidth,frameheight
SetColor 255,255,255
End Function
Function getDimensions()
Local ratio:Float
width = frameWidth
ratio = width / img.width
height = img.height * ratio
If width <=frameWidth And height <= frameHeight
Return
EndIf
height = frameHeight
ratio = height / img.height
width = img.width * ratio
End Function
|