Or here is a memblock free version:
function SaveBitmap(File as string, Bmp as integer)
local x as integer
local y as integer
local c as dword
if file exist(File) then delete file File
open to write 1, File
write byte 1, asc("B")
write byte 1, asc("M")
write long 1, 26+( (bitmap width(Bmp)*3) * bitmap height(Bmp) )
write word 1, 0
write word 1, 0
write long 1, 26
write long 1, 12
write word 1, bitmap width(Bmp)
write word 1, bitmap height(Bmp)
write word 1, 1
write word 1, 24
lock pixels
for y=screen height()-1 to 0 step -1
for x=0 to screen width()-1
c=point(x,y)
write byte 1, rgbb(c)
write byte 1, rgbg(c)
write byte 1, rgbr(c)
next x
next y
unlock pixels
close file 1
endfunction