I create an image of a white circle on a black backround. Then I clear the black backgound pixels' alpha channel and set the white circle pixels' alpha channel to opaque.
Now, when I display the image using ALPHABLEND blend mode, it just displays as if I'm using SOLIDBLEND. I expected the black pixels to not be drawn at all. What have I done wrong?
Now, when I display the image using ALPHABLEND blend mode, it just displays as if I'm using SOLIDBLEND. I expected the black pixels to not be drawn at all. What have I done wrong?
Graphics 800, 600 Const IMAGE_FLAGS:Int = DYNAMICIMAGE | MIPMAPPEDIMAGE Local image:Timage = CreateImage(128, 128, 1, IMAGE_FLAGS) ' Draw white circle on black background & copy to image. SetClsColor 0, 0, 0 Cls SetColor 255, 255, 255 SetBlend SOLIDBLEND DrawOval 0, 0, 128, 128 GrabImage image, 0, 0 SetColor 255, 255, 255 ' Set black pixels to transparent and white pixels to opaque. Local pmap:TPixmap = LockImage(image, 0, False, False) For Local x:Int = 0 To PixmapWidth(pmap)-1 For Local y:Int = 0 To PixmapHeight(pmap)-1 Local p:Int = ReadPixel(pmap, x, y) If p=$FF000000 ' Clear alpha channel (transparent) on black pixels. WritePixel(pmap, x, y, $00000000) Else ' Set alpha channel (opaque) on white pixels. WritePixel(pmap, x, y, $FFFFFFFF) EndIf Next Next UnlockImage image ' Draw alphablended image. SetClsColor 150, 0, 150 Cls SetBlend ALPHABLEND DrawImage image, 10, 10 Flip WaitKey() End