Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One option is to use the AlphaBlend function in Windows.pas unit. Something like this will produce semi-transparent text (with a drop shadow - building on Jim McKeeth's response) overlayed on an image:</p> <pre><code> uses Windows, Graphics; . . . var BackgroundImage: Graphics.TBitmap; { need to call out specifically for Graphics.TBitmap because the Windows unit also has a TBitmap declaration } TextImage: Graphics.TBitmap; BlendFunc: BLENDFUNCTION; begin BlendFunc.BlendOp := AC&#95;SRC&#95;OVER; BlendFunc.BlendFlags := 0; BlendFunc.SourceConstantAlpha := $C0; { a hex value from $00-$FF (0-255). Represents the percent of opaqueness: $00 is completely transparent, $FF is completely opaque. $C0 is 75% opaque } BlendFunc.AlphaFormat := AC&#95;SRC&#95;ALPHA; { BackgroundImage is for holding the image you want to overlay text onto } BackgroundImage := Graphics.TBitmap.Create; try BackgroundImage.LoadFromFile('yourimagehere.bmp'); { Create another TBitmap to hold the text you want to overlay } TextImage := Graphics.TBitmap.Create; try { Set this bitmap to have the same dimensions as the background image you want the text to appear on. } TextImage.Height := BackgroundImage.Height; TextImage.Width := BackgroundImage.Width; { In my limited experience with AlphaBlend, Black is always 100% transparent. So, paint TextImage completely Black. Play around with this to see the effect it has on the final outcome. } TextImage.Canvas.Brush.Color := clBlack; TextImage.Canvas.FloodFill(0, 0, clNone, fsBorder); TextImage.Canvas.Font.Style := [fsBold]; { Write the shadow first } TextImage.Canvas.Brush.Style := bsClear; TextImage.Canvas.Font.Color := clDkGray; TextImage.Canvas.TextOut(11, 11, 'Test'); { Then put the text on top (slightly offset) } TextImage.Canvas.Brush.Style := bsClear; TextImage.Canvas.Font.Color := clMaroon; TextImage.Canvas.TextOut(10, 10, 'Test'); { Use the AlphaBlend function to overlay the bitmap holding the text on top of the bitmap holding the original image. } Windows.AlphaBlend(BackgroundImage.Canvas.Handle, 0, 0, TextImage.Width, TextImage.Height, TextImage.Canvas.Handle, 0, 0, TextImage.Width, TextImage.Height, BlendFunc); { Assign the now updated BackgroundImage to a TImage control for display } Image1.Picture.Bitmap.Assign(BackgroundImage); finally TextImage.Free; end; finally BackgroundImage.Free; end; end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload