MichaelB: Ok I'm having trouble with this. If I load in a TPixmap with LoadPixmap and then use SetBlend ALPHABLEND before drawing it with DrawPixmap I see it on screen, but it is drawn without any alpha. This is even before I've touched your code. However I did try you code also but the object I drew on the pixmap came out with a blocky (non-alpha) outline, it was weird. Any ideas?
Here's my code:
Here's my code:
Strict Function ARGB_Alpha:Int(ARGB:Int) Return Int((ARGB & $FF000000:Int) / $1000000:Int) End Function Function ARGB_Red:Int(ARGB:Int) Return Int((ARGB & $00FF0000:Int) / $10000:Int) End Function Function ARGB_Green:Int(ARGB:Int) Return Int((ARGB & $0000FF00:Int) / $100:Int) End Function Function ARGB_Blue:Int(ARGB:Int) Return (ARGB & $000000FF:Int) End Function Function ARGB_Color:Int(alpha:Int,red:Int,green:Int,blue:Int) Return (Int(alpha*$1000000)+Int(blue*$10000)+Int(green*$100)+Int(RED)) End Function Function DrawOnPixmap(image:TImage, framenr:Int = 0, Pixmap:TPixmap, x:Int, y:Int, alpha:Float = 1.0, light:Float = 1.0) Local TempPix:TPixmap = Null If framenr = 0 Then TempPix = LockImage(image) If framenr > 0 Then TempPix = LockImage(image, Framenr) 'TempPix.convert(image.pixmaps[0].format) For Local i:Int = 0 To ImageWidth(image) - 1 For Local j:Int = 0 To ImageHeight(image)-1 If x+1 < pixmap.width And y+j < pixmap.height Local sourcepixel:Int = ReadPixel(TempPix, i,j) Local destpixel:Int = ReadPixel(pixmap, x+i,y+j) ' Local destA:Int = ARGB_Alpha(destpixel) Local sourceA:Int = ARGB_Alpha(sourcepixel) If sourceA = -1 Then sourceA = 255 * alpha Else sourceA = SourceA * alpha If sourceA <> - 1 Then If sourceA < - 1 Then sourceA = -sourceA Local destR:Int = ARGB_Blue(destpixel) Local destG:Int = ARGB_Green(destpixel) Local destB:Int = ARGB_Red(destpixel) Local SourceR:Int = ARGB_Red(Sourcepixel) Local SourceG:Int = ARGB_Green(Sourcepixel) Local SourceB:Int = ARGB_Blue(Sourcepixel) sourceR = Int(Float(sourceA / 255.0) * Float(sourceR * light)) + Int(Float((255 - sourceA) / 255.0) * Float(destR)) sourceG = Int(Float(sourceA / 255.0) * Float(sourceG * light)) + Int(Float((255 - sourceA) / 255.0) * Float(destG)) sourceB = Int(Float(sourceA / 255.0) * Float(sourceB * light)) + Int(Float((255 - sourceA) / 255.0) * Float(destB)) sourcepixel = ARGB_Color(255, sourceR, sourceG, sourceB) EndIf If sourceA <> 0 Then WritePixel(Pixmap, x + i, y + j, sourcepixel) EndIf Next Next If framenr = 0 UnlockImage(image) If framenr > 0 UnlockImage(image, framenr) End Function Graphics 800,600,0 Local i:TImage = LoadImage("gent.png") Local p:TPixmap = LoadPixmap("newspaper.png") DrawOnPixmap(i,0,p,150,120) While Not KeyHit(key_Escape) Cls SetBlend alphablend DrawPixmap(p,10,10) Flip Wend