Rescaling images involves transfering them to bitmaps and unfortunately bitmaps will discard any alpha information. So, I have written this to scale an image using memblocks.
Thanks to VanB and Batvink for the ideas
`Memblock Scale
`======================
`©Scraggle
`======================
`19th January 2006
load image "BackDrop.jpg",1
load image "Warning.png",2
ResizeImage(2,256,256)
sync on
do
paste image 1,0,0,1
paste image 2,50,50,1
sprite 1,mousex(),mousey(),2
sync
loop
`***********************************
` RESIZE IMAGE USING MEMBLOCKS
`***********************************
Function ResizeImage(Image,NewWidth,NewHeight)
local BmC as integer = 1 `Bitmap Colour
local BmA as integer = 2 `Bitmap Alpha
local BmCs as integer = 3 `Bitmap Colour Scaled
local BmAs as integer = 4 `Bitmap Alpha Scaled
local MbC as integer = 1 `Memblock Colour
local MbA as integer = 2 `Memblock Alpha
local Width as dword `Original Width
local Height as dword `Original Height
`Put original image in a memblock and get its dimensions
make memblock from image MbC , Image
Width = memblock dword(MbC , 0)
Height = memblock dword(MbC , 4)
`Make a coloured alpha version of the memblock
make memblock from image MbA , Image
`Delete the original image for later use
delete image Image
`Replace the Blue channel with the Alpha channel
for x = 0 to Width
for y = 0 to Height
Position = (y * Width * 4) + (x * 4) + 12
if Position < get memblock size(MbA)
Alpha = memblock byte(MbA , Position + 3)
write memblock byte MbA , Position , Alpha
endif
next y
next x
`Put the coloured memblock and the Alpha'd memblock onto bitmaps
make bitmap from memblock BmC , MbC
make bitmap from memblock BmA , MbA
`Delete the memblocks for later use
delete memblock MbC
delete memblock MbA
`Scale both bitmaps
create bitmap BmCs ,NewWidth ,NewHeight
create bitmap BmAs ,NewWidth ,NewHeight
copy bitmap BmC ,0,0,Width,Height ,BmCs ,0,0,NewWidth,NewHeight
copy bitmap BmA ,0,0,Width,Height ,BmAs ,0,0,NewWidth,NewHeight
`Get two new memblocks from the scaled bitmaps
make memblock from bitmap MbC , BmCs
make memblock from bitmap MbA , BmAs
`Copy the contents of the blue channel of the
`Alpha'd memblock to the alpha channel of the other
for x = 0 to NewWidth
for y = 0 to NewHeight
Position = (y * NewWidth * 4) + (x * 4) + 12
if Position < get memblock size(MbA)
Alpha = memblock byte(MbA , Position)
write memblock byte MbC , Position + 3 , Alpha
endif
next y
next x
`Create a final scaled image from the resultant memblock
make image from memblock Image , MbC
`Clear up unwanted memblocks and bitmaps
delete memblock MbA
delete memblock MbC
delete bitmap BmA
delete bitmap BmC
delete bitmap BmCs
delete bitmap BmAs
EndFunction