change individual colour of an image to another

BlitzMax Forums/BlitzMax Beginners Area/change individual colour of an image to another

Hi Fellas

Is it possible to change an individual colour of an image to another colour? If yes, how?

Cheers

Not using the normal command set. You could read the pixels in the imange and change them that way.

you basically would have to 'search and replace' a given pixel value.

You *could* set the mask colour to the pixel colour then draw it over a rect the same size that is the actual colour you want then grab it.

Thanks very much for your suggestions guys.

Here's some code I use
' // Images //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
SetMaskColor 255, 0, 255
Global imgHunter:TImage = LoadImage(foldername$ + "/suit_c1.png", MASKEDIMAGE)

SetColor 255, 255, 255
SetClsColor 255, 0, 255
Cls

DrawImage imgHunter, 0, 0

myPix:TPixMap = GrabPixmap(0,0,ImageWidth(imgHunter), ImageHeight(imgHunter))

For y = 0 To ImageHeight(imgHunter) - 1
	For x = 0 To ImageWidth(imgHunter) - 1
		argb = ReadPixel(myPix, x, y)
		Red = ARGB Shr 16 & 255
		Green = ARGB Shr 8 & 255
		blue = ARGB Shr 0 & 255
		If Red = 104 And Green = 107 And Blue = 234 Then ' Brightest
			SetColor colorRed[0], colorGreen[0], colorBlue[0]
			DrawRect x, y, 1, 1
		ElseIf Red = 50 And Green = 54 And Blue = 216 Then 
			SetColor colorRed[1], colorGreen[1], colorBlue[1]
			DrawRect x, y, 1, 1
		ElseIf Red = 39 And Green = 39 And Blue = 141 Then 
			SetColor colorRed[2], colorGreen[2], colorBlue[2]
			DrawRect x, y, 1, 1
		ElseIf Red = 22 And Green = 23 And Blue = 56 Then 
			SetColor colorRed[3], colorGreen[3], colorBlue[3]
			DrawRect x, y, 1, 1
		EndIf		
		FlushMem
	Next
Next

SetColor colorRed[0], colorGreen[0], colorBlue[0]
DrawRect ImageWidth(imgHunter) - 16, ImageHeight(imgHunter) - 16, 16, 16

my_pixmap:tpixmap=GrabPixmap(0,0,ImageWidth(imgHunter), ImageHeight(imgHunter))

SavePixmapPNG my_pixmap, "tmp.png", 0
system_ "pngcrush.exe tmp.png " + foldername$ + "/suit_c" + colorNum + ".png"
DeleteFile "tmp.png"