Try converting your Timage to TPixmap. Then read in each pixels alpha value and set the color of pixel. Below is something I whipped up. May not be the fastest but it works as advertised :-)
SuperStrict
Graphics(800, 600, 0, 30)
Local iImage:TImage = LoadImage("r:/temp/barn.png") 'Change to your image
Local oImage:TImage = LoadImage(alphaToColor(iImage, $ff, 0, 0))
SetBlend(ALPHABLEND)
While Not KeyHit(KEY_ESCAPE) And Not AppTerminate()
Cls()
DrawImage(oImage, 0, 0)
Flip(-1)
Wend
Function alphaToColor:TPixmap(im:TImage, r:Int, g:Int, b:Int)
'Returns Pixmap with color changed based on alpha
Local i:TPixmap
Local i2:TPixmap = CreatePixmap(im.width, im.height, PF_RGBA8888)
Local p:Int, pr:Int,al:Int
i = LockImage(im)
Local x:Int, y:Int
For y = 0 Until i.height
For x = 0 Until i.width
p = 0
pr = i.ReadPixel(x, y)
al = (pr & $ff000000) 'al now has alpha value
If al = 0 'USE THIS IF STATMENT TO TEST WHEN YOU TOWANT REPLACE THE ALPHA WITH YOUR SPECIFIED COLOR
pr = $ff000000 | (r Shl 16) | (g Shl 8) | b
End If
i2.WritePixel(x, y, pr)
Next
Next
UnlockImage(im)
Return i2
End Function
|