Lazarus

Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: zxandris on December 21, 2024, 03:46:09 pm

Title: Drawing text with opacity - [Solved]
Post by: zxandris on December 21, 2024, 03:46:09 pm
This is probably a really simple question, but i can't find a way to do it, at least seting the alpha what have you.  In short I am writing text to a bgra bitmap, and I would like to write the text with opacity, in other words, slightly see through.  How would I do that please?

Thanks in advance,

CJ
Title: Re: Drawing text with opacity
Post by: lainz on December 21, 2024, 05:30:50 pm
Specify the color like this BGRA(255,255,255,100) where 100 is the opacity from 0 (fully transparent) to 255 (fully opaque).
Title: Re: Drawing text with opacity
Post by: zxandris on December 21, 2024, 05:50:08 pm
I am trying that, but it doesn't appear to be working, here's my code for setting the font stuff

Code: Pascal  [Select][+][-]
  1.         // Set the font options, need this for calculations
  2.         BgraOutput.Canvas.Font.Name := lbl.FontFace;
  3.         BgraOutput.Canvas.Font.Size := lbl.FontSize;
  4.         BgraOutput.Canvas.Font.color := ColorToBgra(lbl.FontColor, lbl.Alpha);
  5.         BgraOutput.FontHeight := lbl.FontSize;
  6.         BgraOutput.FontName := lbl.FontFace;
  7.         BgraOutput.FontStyle := [];
  8.         if lbl.Bold then BgraOutput.FontStyle := BgraOutput.FontStyle + [fsBold];
  9.         if lbl.Italic then BgraOutput.FontStyle := BgraOutput.FontStyle + [fsItalic];
  10.         if lbl.Underlined then BgraOutput.FontStyle := BgraOutput.FontStyle + [fsUnderline];
  11.  

And it doesn't appear to work.

I imagine this
Code: Pascal  [Select][+][-]
  1.  ColorToBgra(lbl.FontColor, lbl.Alpha);
  2.  

Is the problem, and I optionally render the text I'm writing with a renderer but not when I'm trying this out and the text doesn't appeaer to change the alpha at all which is stored in the record there,.

Specify the color like this BGRA(255,255,255,100) where 100 is the opacity from 0 (fully transparent) to 255 (fully opaque).
Title: Re: Drawing text with opacity
Post by: lainz on December 21, 2024, 05:54:18 pm
Your code looks wrong...

Please follow the tutorial here:
https://wiki.freepascal.org/BGRABitmap_tutorial_12

And change for example BGRABlack with BGRA(0,0,0,100)
Title: Re: Drawing text with opacity
Post by: zxandris on December 21, 2024, 05:58:43 pm
Yeah I didn't actually set the color on TextOut, my bad,but thanks to that reminder I checked the relevant area of code and now it works!  sorry about that, that was me being blind and a little silly!

Code: Pascal  [Select][+][-]
  1.                
  2. BgraOutput.TextOut(intX, intY, strOutput, ColorToBgra(lbl.FontColor, lbl.Alpha));
  3.  

Was what I needed to change, thanks for all your help!

CJ

Your code looks wrong...

Please follow the tutorial here:
https://wiki.freepascal.org/BGRABitmap_tutorial_12

And change for example BGRABlack with BGRA(0,0,0,100)
TinyPortal © 2005-2018