|
image - handle of the image to resize width# - new width in pixels height# - new height in pixels |
|
Resizes an image to an exact pixel size, replacing it in memory. It is ScaleImage stated in pixels rather than multipliers, which is the easier way round when the target size is what you actually know: fitting a photo into a 128x128 portrait box, stretching a background to GraphicsWidth() by GraphicsHeight(), or squeezing a loaded picture into a fixed inventory slot. The parameters are floats, so a fractional size is accepted, and the aspect ratio is entirely up to you - nothing is preserved unless you work it out yourself from ImageWidth and ImageHeight. Like all the image transforms this rebuilds the image in software and is much too slow for a game loop. Do it once while loading, and resize a CopyImage rather than the original if you still need the source at full size. Every frame of an animated image is resized, and the result is smoothed or left blocky according to TFormFilter. Resizing throws information away, so going small and then large again will not recover the detail. Always start from the original. See also: ScaleImage, RotateImage, TFormFilter, ImageWidth, ImageHeight. |
; ResizeImage Example
; -------------------
Graphics 640,480,0,2
SetBuffer BackBuffer()
; Keep a pristine original - ResizeImage changes the image itself,
; so we always resize a fresh copy to avoid quality loss stacking up
original=LoadImage("media/b3dlogo.jpg") ; 400x197 photo
new_w=200
resized=CopyImage(original)
ResizeImage resized,new_w,new_w*197/400
While Not KeyDown(1)
Cls
; [ / ] pick a new width; the height keeps the same proportions.
; ResizeImage is slow - do it on a keypress, never every frame.
If KeyHit(26) And new_w>100 Then
new_w=new_w-50
FreeImage resized
resized=CopyImage(original)
ResizeImage resized,new_w,new_w*197/400
End If
If KeyHit(27) And new_w<400 Then
new_w=new_w+50
FreeImage resized
resized=CopyImage(original)
ResizeImage resized,new_w,new_w*197/400
End If
DrawImage original,20,70
DrawImage resized,20,290
Text 0,50,"Original 400x197"
Text 0,270,"ResizeImage resized,"+new_w+","+(new_w*197/400)+" now "+ImageWidth(resized)+"x"+ImageHeight(resized)
Text 0,0,"[ / ] : resize smaller / larger Esc: exit"
Flip
Wend
End