Can anybody help

BlitzMax Forums/BlitzMax Programming/Can anybody help

VinceA(Posted 2008) [#1]
I want to automate the maskcolor setting for my App
For Local i:Int = 0 Until 4
	Local pic:TImage = LoadImage("pic.png")
	Local pm:TPixmap = LockImage(pic) 
	Local px:Int = ReadPixel(pm,ImageWidth(pic)-1,1)

	Local r:Byte = px Shr 16
	Local g:Byte = px Shr 8
	Local b:Byte = px
	
	SetMaskColor(r,g,b)

	Print r
	Print g
	Print b
Next


This only work everyother time.. ?
Can anybody help me


Dreamora(Posted 2008) [#2]
Mask colors only impact pixmaps / images loaded afterwards. stuff loaded before will not be affected.


VinceA(Posted 2008) [#3]
Thanks a lot for the respond. However I already knew that. I think I need to explain a little better. What I want to do is the same as what game-maker does. I want to first analyze the image to find its maskcolor, and then load it - again. In this way I don’t always have to set the maskcolor, it will automatically be read (maskcolors can be tricky, and require a lot of trial and error).

Maybe the problem is reading a pixel value after the image has been masked. It seems that the first time it reads the pixel its fine, and sets that maskcolor to the color of this pixel. The next time the image is already masked so it just reads r=0, g=0 and b=0. As this new value is now set to a maskcolor it can now read the pixel again. So it works every other time.

Moral of the story: You cant read a masked pixel!... I guess


tonyg(Posted 2008) [#4]
VinceA, You're right.
Loading with setmaskcolor 255,0,0 will change all pixels to 0,0,0.
Graphics 800,600
'uncomment to see the affect of setmaskcolor
'SetMaskColor 255,0,0
Local image:timage=LoadImage("red.png")
Local mypixmap:TPixmap=LockImage(image)
For Local x:Int=0 To ImageWidth(image)-1
	For Local y:Int=0 To ImageHeight(image)-1
		Print ReadPixel(mypixmap,x,y)
	Next
Next



VinceA(Posted 2008) [#5]
This will work as long as none of the color parameters are set to - 0.
It kind of a workaround, but it seems to work

Graphics 640, 480, 0
'Loading an Masked Image, where the top right pixel
'will be set as the maske color
'!! Mask colors must be from 1-255 for each channel 

Local maskImg:TImage = LoadImageMasked("DarkRed.png")
Local maskImg1:TImage = LoadImageMasked("DarkRed.png")
Local maskImg2:TImage = LoadImageMasked("DarkRed.png")

While Not KeyDown(KEY_ESCAPE)
	Cls
	SetBlend MASKEBLEND
	DrawImage maskImg,0,0
	DrawImage maskImg1,0,64
	DrawImage maskImg2,0,128
	Flip
Wend
End

Function LoadImageMasked:TImage(imgName:String)
	Local img:TImage = LoadImage(imgName)
	Local pm:TPixmap = LockImage(img) 
	Local px:Int = ReadPixel(pm,ImageWidth(img)-1,1)
	Local r:Byte = px Shr 16
	Local g:Byte = px Shr 8
	Local b:Byte = px
	
	'If The mask color is the same then skip SetMaskColor
	'With out this only every other img if same mask color
	'will work
	If r<>0 And g<>0 And b<>0 Then
		SetMaskColor(r,g,b)
	End If
	
	'Clean Up
	img = Null
	pm = Null
	px = Null
	r = Null
	g = Null
	b = Null
	GCCollect
	Return LoadImage(imgName,MASKEDIMAGE)
End Function