|
image - handle of the image to scale xscale# - horizontal multiplier; 1.0 leaves the width alone, 2.0 doubles it, 0.5 halves it yscale# - vertical multiplier, same scale |
|
Resizes an image by a multiplier, replacing it in memory. The numbers are factors, not pixels: 1.0 is unchanged, 2.0 is twice as big, 0.25 is quarter size. Negative values mirror the image, so -1.0,1.0 gives you a left-facing copy of a right-facing sprite - the cheapest way to get both directions out of one drawing. Use ResizeImage instead when you want to hit an exact pixel size. This changes the image itself rather than drawing a scaled copy, and it happens in software, one pixel at a time. It is far too slow to run inside your main loop. Build the sizes you need at startup - usually by taking a CopyImage of the original and scaling the copy, so you keep the master intact - and then just draw the right one. Every frame of an animated image is scaled, and the scaling pivots around the image's handle. ImageWidth and ImageHeight report the new size afterwards. Scaling is destructive: each pass throws pixels away or invents them, so scaling down and back up will not get your original detail back, and repeated scaling of the same handle turns to mush. Always scale from a fresh copy of the original. TFormFilter controls whether the result is smoothed or left blocky, which matters for pixel art. See also: ResizeImage, RotateImage, TFormFilter, CopyImage, ImageWidth. |
; ScaleImage Example
; ------------------
Graphics 640,480,0,2
SetBuffer BackBuffer()
; Keep a pristine original - ScaleImage changes the image itself,
; so we always scale a fresh copy to avoid quality loss stacking up
original=LoadImage("media/b3dlogo.jpg") ; 400x197 photo
factor#=0.5
flip_sign=1
scaled=CopyImage(original)
ScaleImage scaled,factor,factor
While Not KeyDown(1)
Cls
; [ / ] change the scale, F mirrors with a negative x scale.
; ScaleImage is slow - do it on a keypress, never every frame.
changed=0
If KeyHit(26) And factor>0.25 Then
factor=factor-0.25
changed=1
End If
If KeyHit(27) And factor<1.0 Then
factor=factor+0.25
changed=1
End If
If KeyHit(33) Then
flip_sign=-flip_sign
changed=1
End If
If changed=1 Then
FreeImage scaled
scaled=CopyImage(original)
ScaleImage scaled,factor*flip_sign,factor
End If
DrawImage original,20,70
DrawImage scaled,20,290
Text 0,50,"Original 400x197 (scale 1.0)"
Text 0,270,"ScaleImage scaled,"+(factor*flip_sign)+","+factor+" now "+ImageWidth(scaled)+"x"+ImageHeight(scaled)
Text 0,0,"[ / ] : scale down / up F: mirror (negative scale) Esc: exit"
Flip
Wend
End