Working on an editor and need a function that resixed an image to be used as a thumbnail, so I wrote this...
Function resizeimage( image, xsize# as float , ysize# as float )
resized = find free image()
local scax#, scay#, xp#, yp# as float
w = image width(image) : h = image height(image)
scax# = (w)/(xsize#) : scay# = (h)/(ysize#)
dim pixel( w, h )
Paste Image image, 0, 0
Lock Pixels
for x = 0 to w
for y = 0 to h
pixel( x, y ) = point( x, y )
next y
next x
for x = 0 to w
for y = 0 to h
col = rgb( rgbr(pixel( x, y )), rgbg(pixel( x, y )), rgbb(pixel( x, y )) )
xp# = x/scax#
yp# = y/scay#
dot xp#, yp#, col
next y
next x
Unlock Pixels
Get Image resized, 0, 0, xsize#, ysize#, 1
undim pixel()
cls
endFunction resized
It can only be used for scaling object down
e.g.
taking an image of 256x256 can only be resized to a smaller size, such as 128x128
See it in action
Just made a new one, takes about 20ms to resize, and it can scale up and down
function resizeImage( img, xsize, ysize )
fs = find free sprite()
sprite fs, 0, 0, img
Size Sprite fs, xsize, ysize
Paste Sprite fs, 0, 0
rimg = find free image()
get image rimg, 0, 0, xsize, ysize, 1
cls
Delete Sprite fs
endFunction rimg
Yours
N3wton