Recent

Author Topic: [SOLVED] How to create image negative to background color?  (Read 5773 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1048
[SOLVED] How to create image negative to background color?
« 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
« Last Edit: November 01, 2011, 09:55:31 pm by Dibo »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: How to create image negative to background color?
« Reply #1 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.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: How to create image negative to background color?
« Reply #2 on: November 01, 2011, 09:55:18 pm »
Thanks, this is what I needed.

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: [SOLVED] How to create image negative to background color?
« Reply #3 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.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018