Lazarus

Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: Dibo on November 01, 2011, 07:18:41 pm

Title: [SOLVED] How to create image negative to background color?
Post by: Dibo on November 01, 2011, 07:18:41 pm
Hi,

I have TPaintBox and TBGRABitmap with some logo in PNG format. This logo is only in one color (e.g. white). Can I draw it so that it is visible on the light and dark background? Look at attachments. This is only fake demo with TLabel as Logo. If user have dark system theme then logo should be white, if he have light theme then it should be dark. Is it possible?

Regards
Title: Re: How to create image negative to background color?
Post by: Blaazen on November 01, 2011, 08:06:04 pm
In unit Graphics is function
Code: [Select]
function InvertColor(AColor: TColor): TColor; 
if you need to invert Label.Font.Color

You will probably need to detect whether the theme is light or dark.
I would take the background color (probably clForm) and convert it to RGB:
Code: [Select]
function ColorToRGB(Color: TColor): Longint;   
Separete it to R, G and B and make R+G+B. You will get result from 0 to (3*255).
High result = light theme, low result = dark theme.
Title: Re: How to create image negative to background color?
Post by: Dibo on November 01, 2011, 09:55:18 pm
Thanks, this is what I needed.
Title: Re: [SOLVED] How to create image negative to background color?
Post by: circular on November 01, 2011, 10:37:22 pm
By the way, if you want to invert a bitmap, you can call "Negative" function. But if you draw the text, you can compute the best color like Blaazen told you.
TinyPortal © 2005-2018