I'm not 100% sure I get what you mean, but I think you want to draw semi-transparent text onto an image. If that's the ticket, there are several ways to do it. Here's one of the simplest, a homebrewed solution using nearly all PB native functions, just a touch of API:
Code: Select all
; Some mischief for a Friday evening...
; by netmaestro
Procedure ConvertToAlpha(image, transcolor, intensity)
Structure BGRA
blue.c
green.c
red.c
alpha.c
EndStructure
GetObject_(ImageID(image), SizeOf(BITMAP), bmp.BITMAP)
*bits.BGRA = bmp\bmBits
For i=0 To bmp\bmHeight-1
For j=0 To bmp\bmWidthBytes-1 Step 4
*px.BGRA = *bits + bmp\bmWidthBytes * i + j
If *px\blue=Blue(transcolor) And *px\green=Green(transcolor) And *px\red=Red(transcolor)
*px\alpha = 0
Else
*px\alpha = intensity
EndIf
Next
Next
EndProcedure
;================================================================================
; Step 1
; Create a 32-bit image to use for your text
; Make the background color close to the text color, just noticeably darker
; Draw your text on the background
;================================================================================
LoadFont(0, "Arial", 48, #PB_Font_Bold|#PB_Font_HighQuality)
CreateImage(0, 400, 70, 32)
StartDrawing(ImageOutput(0))
Box(0,0,400,70,RGB(230,0,0))
DrawingFont(FontID(0))
DrawText(0,0, "Alpha Text", #Red, RGB(230,0,0))
StopDrawing()
;================================================================================
; Step 2
; Apply an alpha value to all non-transparent pixels in your text image
; using the supplied ConvertToAlpha procedure
;================================================================================
ConvertToAlpha(0, RGB(230,0,0), 90)
;================================================================================
; Step 3
; Create or load an image of any desired depth to draw the text on
; here we'll just create one
;================================================================================
CreateImage(1, 600,400)
StartDrawing(ImageOutput(1))
Box(0,0,200,200,#White)
Box(200,0,200,200,#Gray)
Box(400,0,200,200,#White)
Box(0,200,200,200,#Gray)
Box(200,200,200,200,#White)
Box(400,200,200,200,#Gray)
StopDrawing()
;================================================================================
; Step 4
; Use PureBasic's DrawAlphaImage command to imprint the text on the image
;================================================================================
StartDrawing(ImageOutput(1))
DrawAlphaImage(ImageID(0), 110, 160)
StopDrawing()
;================================================================================
; You're finished! Give it a test:
;================================================================================
OpenWindow(0,0,0,600,400,"",$CA0001)
CreateGadgetList(WindowID(0))
ImageGadget(0,0,0,0,0,ImageID(1))
Repeat:Until WaitWindowEvent()=#WM_CLOSE