I always have this problem too. It is saying that your memblock hasn't been created yet. It does this when you make the image inside the program instead of loading it from outside.
What you do to stop to this is sync after you get the image like this:
get image 1,0,0,10,10
sync
make memblock from image 1,1
Here's your fixed code:
I accidentally changed the function into a gosub, while trying to figure out the problem. You can probably figure out how to put it back into one now. If not, I'm always glad to help.
sync on : hide mouse : randomize timer()
for x=0 to 200
for y=0 to 200
ink rgb(rnd(255),rnd(255),rnd(255) ),0
dot x,y
next y
next x
get image 1,0,0,200,200
cls rgb(0,255,0)
ink rgb(255,0,0),0
box 50,50,150,150
get image 2,0,0,200,200
sync
green_screen(2,1,3)
paste image 2,0,0
ink rgb(255,255,255),0
center text 100,230,"Old Image / "
sync
repeat
sync
until spacekey()=1
cls rgb(0,255,0)
paste image 3,0,0
center text 100,230,"New Image / "
sync
do : sync : loop
function green_screen(original_image,background_image,new_image)
make memblock from image 1,original_image
make memblock from image 2,background_image
make memblock 3,get memblock size(1)
write memblock dword 3,0,memblock dword(1,0)
write memblock dword 3,4,memblock dword(1,4)
write memblock dword 3,8,memblock dword(1,8)
for pos=12 to get memblock size(3)-2 step 2
xycolor = memblock word(1,pos)
if xycolor < rgb(20,255,20) and xycolor > rgb(0,235,0)
write memblock word 3,pos,memblock word(2,pos)
else
write memblock word 3,pos,memblock word(1,pos)
endif
next pos
make image from memblock new_image,3
endfunction
green_screen:
make memblock 3,get memblock size(2)
write memblock dword 3,0,memblock dword(2,0)
write memblock dword 3,4,memblock dword(2,4)
write memblock dword 3,8,memblock dword(2,8)
for pos=12 to get memblock size(3)-2
xycolor = memblock word(2,pos)
if xycolor < rgb(20,255,20) and xycolor > rgb(0,235,0)
write memblock word 3,pos,memblock word(1,pos)
else
write memblock word 3,pos,memblock word(2,pos)
endif
next pos
make image from memblock 3,3
return
By the way, if an image is created in DB, its normally going to be a 16 bit image, unless you manually change it, but besides that it's going to be 16 bit. So, your getting the pixels for a 16 bit image, you wouldn't use dword, you would use word.
Just saying that, because I also had to change where you were looking for the pixels and using dword, instead of word.