Create white image mask

BlitzMax Forums/BlitzMax Programming/Create white image mask

maverick69(Posted 2005) [#1]
I don't know if it's possible using BMax to draw a white image mask of an image (for example in a shoot'em'up to give some feedback that an enemy is hit). So I've wrote a few lines of code to load in a image that will be converted to a white masked image and finally it works. ;)

Can someone please have a look at it if everthings ok with that code because I'm not very experienced with all that readpixel/writepixel stuff. If there is an easier way to get the same effect it would be nice if you share it with me :-)

Function LoadAnimImageMask:TImage(url:Object,w:Int, h:Int, firstcell:Int, count:Int)
	Local img:TImage = LoadAnimImage(url,w,h,firstcell,count,DYNAMICIMAGE|MASKEDIMAGE|FILTEREDIMAGE)

	For frame:Int = 0 To count-1
		Local pmap:TPixmap = LockImage(img,frame)
		For x:Int = 0 To PixmapWidth(pmap)-1
			For y:Int = 0 To PixmapHeight(pmap)-1
				Local pixel:Int = ReadPixel(pmap,x,y)
				If (pixel <> %111111111111111111111111)
					WritePixel(pmap,x,y,%11111111111111111111111111111111)
				End If
			Next
		Next
		UnlockImage(img,frame)
	Next		
	Return img
End Function



JazzieB(Posted 2005) [#2]
You're along the right lines, but I think you've got your bit manipulation calculations wrong. Also, use Hex, it's a bit easier to read...

If (pixel & $ff000000) Then
  WhitePixel pmap,x,y,$ffffffff
EndIf

This does a bitwise check on the alpha channel of your image and writes a pure whilte, fully opaque pixel to the destination image where the alpha channel is greater than 1.