Mask after Load?

BlitzMax Forums/BlitzMax Programming/Mask after Load?

I managed to mask an image if I do it before I loading it but I can't manage to mask an image "on the fly" in the gameloop. The idea I had was to first pick a normal maskcolor(background), then I would pick another color as mask and then paint a rect or something behind my image(Tank). In this way I'll be able to create players/ships/etc with a wide selection of colors. But even thou I use SetBlend(AlphaBlend) or SetBlend(MaskBlend) nothing happens to the image.

'Shouldn't this work?

SetMaskColor 255,255,0
SetBlend(MASKBLEND)
DrawImage Image,BX,BY


I'd be very interested in the answer to this as well.
From another topic it was stated that the maskcolor needs to be determined at loadtime or else a pixmap is required to alter the image (2 pixmaps? 1 of the image and another to mask?)
If true then it's a step backwards.
<edit> sorry, that's a bit harsh.. something that I'd like to see changed.

Yea, I'll check out if pixmaps can change the problem

This is what I came up with...
Graphics 640,480,16
back = LoadImage("back.png")
front = LoadImage("masked.png",dynamicimage)
While Not KeyDown(key_escape)
   If Keydown(key_space)
      burb = 255
   Else 
      burb = 128
   endif
   DrawImage back,100,100
   tg_pixmap = LockImage(front)
   tg1_pixmap = MaskPixmap(tg_pixmap,burb,0,burb)
   UnlockImage(front)
   DrawPixmap tg1_pixmap,100,100
   DrawText "burb : " + burb,0,120
   Flip
   cls
   release tg_pixmap
   release tg1_pixmap
   flushmem
wend
end

where back.png is 100*100 coloured rectangle (in my case 63,175,47) and masked.png is 100*100 coloured rec (223,0,0) with smaller rec of 255,0,255.
If there is a way to copy tg1_pixmap back to a 'normal' image it might do the job.
<edit> for better example.

Great example! It really got me going =)

I figured that you don't really need both tg_pixmap and tg1_pixmap, I used tg_pixmap at both places and it worked fine or am I missing something?

And I have a question, why do you release the pixmap each frame?

My tanks is now running around in different colors =) So it works fine, I used grabimage to get it all together into one image.

It seems like BlitzMax new way to handle images require pixmaps in this way. Still feels a bit strange you can't change the maskcolor after you loaded the image. Anyway if this is the case then I think it should be added to the documentation.

I found the memory increasing so release the pixmaps to keep it under control.
Hmmm.. I get an unhandled exception if I try to use the same pixmap for the lockimage and maskpixmap.
How exactly did you use the same pixmap for both?
I agree that BMX needs to use pixmap as images can not be changed on the fly but it is a shame. B3D had maskimage done quite nicely.
I'm assuming you had to draw the pximap then grabimage to get the new image... is that right? If you found a more elegant way I'd be interested.

Yes I draw it all, then I copy that part to a new image with grabimage.

Graphics 640,480,16
back = LoadImage("back.png")
front = LoadImage("masked.png",dynamicimage)
'back.png is 100*100 coloured rectangle (in my Case 63,175,47) And masked.png is 100*100 coloured rec (223,0,0) with smaller rec of 255,0,255

While Not KeyDown(key_escape)
   If KeyDown(key_space)
      burb = 255
   Else 
      burb = 128
   EndIf
   
   SetColor 0,0,255
   DrawRect 50,50,200,200
   'DrawImage back,100,100
   SetColor 255,255,255
   
   SetColor 0,0,255'color of this tank
   DrawRect 50,50,200,200
   tg_pixmap = LockImage(front)
   tg_pixmap = MaskPixmap(tg_pixmap,burb,0,burb)
   UnlockImage(front)

   DrawPixmap tg_pixmap,100,100
   DrawText "burb : " + burb,0,120

   Flip
   Cls
   Release tg_pixmap
   FlushMem
Wend
End