Forum > BGRABitmap and LazPaint

[SOLVED] How to create image negative to background color?



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?


In unit Graphics is function

--- Code: ---function InvertColor(AColor: TColor): TColor; 

--- End code ---
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: ---function ColorToRGB(Color: TColor): Longint;   

--- End code ---
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.

Thanks, this is what I needed.

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.


[0] Message Index

Go to full version