I'm sorry to ask this question, but I already read a lot about alphablending and still can't get it to work. So I really hope you can help me.
The problem:
- First I created a completely black image #1
- Then I created a white image #2 with some yellow text on it [I used drawtext() for the yellow writing]
- Now I want to draw image #2 in image #1 [using drawimage() ], but the white color of image #2 must be transparent, so the result should be a black image with the yellow writing on it.
I tried all I know using drawingmode() or RBGA()-colors, but nothing worked. Can anyone pleeeeeaaaaase post a short source code for it?
Alphablend question
Re: Alphablend question
You have to created image #2 with a transparent background, not with white as color, and with a depth of 32Bit !
Re: Alphablend question
Experiment with this
Code: Select all
Size.i = 128
CreateImage(0, Size, Size, 32, #Blue) ; Background image (blue)
CreateImage(1, Size, Size, 32, #PB_Image_Transparent) ; Foreground text (yellow on transparent)
LoadFont(0, "Arial", Size/5)
If StartDrawing(ImageOutput(1))
DrawingFont(FontID(0))
DrawingMode(#PB_2DDrawing_AllChannels)
#YellowOpaque = #Yellow | $FF000000 ; or RGBA(255, 255, 0, 255)
#YellowTransparent = #Yellow ; or RGBA(255, 255, 0, 0)
DrawText(5, 5, "Hello!", #YellowOpaque, #YellowTransparent)
; or
;DrawingMode(#PB_2DDrawing_AlphaBlend)
;DrawText(5, 5, "Hello!", RGBA(255, 255, 0, 255), RGBA(255, 255, 0, 0))
StopDrawing()
EndIf
If StartDrawing(ImageOutput(0)) ; Draw foreground onto background
DrawAlphaImage(ImageID(1), 0, 0)
StopDrawing()
EndIf
If SaveImage(0, GetTemporaryDirectory() + "temp.bmp")
RunProgram(GetTemporaryDirectory() + "temp.bmp")
EndIf
-
- User
- Posts: 32
- Joined: Tue Jan 12, 2010 4:56 pm
Re: Alphablend question
Thank you so much - finally it works!!!!