[Solved] Darken TColor lazarus / 39-Graphics ---------------------------------------------------------------------- Mike.Cornflake · 2014-06-26 07:36 I'm ignorant in the world of image processing.   I'm highlighting rows in a grid by setting Color in OnPrepareCanvas (according to calculated criteria - bad = red, good = green, OKish = Yellow or Orange.  Unimportant = white.  The unimportant selected rows are highlighted in light gray automatically for me by the grid itself) If the row is the selected row, I want to to highlight the row with a slighter darker version of the color.  Instead of hard-coding alternatives, is there a simple DarkenColor(AColor: TColor; APercent: Double): TColor anywhere?  (Or equivalent) I've looked, and the ones I can find are in dedicated image processing libraries, which I *think* involves introducing levels of complexity beyond what I'm actually after... ---------------------------------------------------------------------- taazz · 2014-06-26 08:04 use GraphUtil.ColorAdjustLuma or search for colorblend for alphablending two colors with a standart alpha value creating something like a chromasity ee a blue window on top of the back color. ---------------------------------------------------------------------- wp · 2014-06-26 08:06 That's the way I did it in fpspreadsheetgrid. It darkens a bright color and brightens a dark color: Code: [Select]function CalcSelectionColor(c: TColor; ADelta: Byte) : TColor; type   TRGBA = record R,G,B,A: Byte end; begin   c := ColorToRGB(c);   TRGBA(Result).A := 0;   if TRGBA(c).R < 128     then TRGBA(Result).R := TRGBA(c).R + ADelta     else TRGBA(Result).R := TRGBA(c).R - ADelta;   if TRGBA(c).G < 128     then TRGBA(Result).G := TRGBA(c).G + ADelta     else TRGBA(Result).G := TRGBA(c).G - ADelta;   if TRGBA(c).B < 128     then TRGBA(Result).B := TRGBA(c).B + ADelta     else TRGBA(Result).B := TRGBA(c).B - ADelta; end; ---------------------------------------------------------------------- Mike.Cornflake · 2014-06-26 08:34 Many thanks @taazz and @wp, I'll play with both solutions :-) ---------------------------------------------------------------------- Blaazen · 2014-06-26 09:12 Quoteuse GraphUtil.....I didn't know this unit at all! I reinvented some methods in EC-Controls (NormalizeRect, GetMonochromaticColor, maybe more). I'll refactore the code. Also unit GraphMath is interesting. Anyway, thanks. ---------------------------------------------------------------------- Mike.Cornflake · 2014-06-26 09:21 Quote from: Blaazen on June 26, 2014, 11:12:57 amQuoteuse GraphUtil.....I didn't know this unit at all! There's a bucketload of undiscovered goodies all around :-) And I've just noticed your tagline QuotePOKE 54296,15Wow, that takes me back :-) ---------------------------------------------------------------------- Mike.Cornflake · 2014-06-26 16:28 Again, many thanks all.  I ended up going with Code: [Select]oColor := GetHighLightColor(oColor, 32);GetHighlightColor is defined in GraphUtil. ---------------------------------------------------------------------- Mike.Cornflake · 2018-08-29 17:41 Quote from: wp on June 26, 2014, 10:06:42 amThat's the way I did it in fpspreadsheetgrid. It darkens a bright color and brightens a dark color: Apologies for re-opening an old topic, but thanks are due:   I just had to fix an issue where I was darkening a row all the way to blackness.  I resolved by popping back here and using @wp's solution instead.  So many thanks @wp :-)