|
-
Mar 15th, 2006, 03:46 AM
#1
[RESOLVED] Algo to detect Light or Dark color
If you change desktop background to a lighter color, Windows autometically changes icon font color to black. If you change it to a darker color, it changes the font color to white.
How it detects which color is lighter and which color is darker ?
-
Mar 15th, 2006, 03:48 AM
#2
Re: Algo to detect Light or Dark color
Colours are stored simply as integer values. You can either test if the sum of all colour parts (the whole number, in other words) is less than a threshold value, or you can break it in to its RGB components and test each of those individually.
-
Mar 15th, 2006, 03:51 AM
#3
Re: Algo to detect Light or Dark color
I think testing the "hue" of the color is easier!
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Mar 15th, 2006, 03:52 AM
#4
Re: Algo to detect Light or Dark color
Saturation, rather. But colours on Windows are stored as RGB, so it's less efficient to convert to an HSB value first 
To split a compound DWORD RGB value:
Code:
red = rgbValue & 0xff
green = (rgbValue & 0xff00) \ 0xff
blue = rgbValue \ 0xff00
-
Mar 15th, 2006, 04:04 AM
#5
Re: Algo to detect Light or Dark color
Yes. I know about RGB extraction.
But I guess testing the sum of all colour parts will not help here.
For example, change desktop color to following RGB values:
RGB(100,255,100) => Text color changes to Black
RGB(255,100,100) => Text color changes to Black
RGB(100,100,255) => Text color changes to White
There must be some other algo that checks which color is darker to human eye.
...And how do you check hue/saturation through VB code ? (.NET has them in COLOR sructure, but what is in VB ?)
Last edited by iPrank; Mar 15th, 2006 at 04:20 AM.
-
Mar 15th, 2006, 04:27 AM
#6
Re: Algo to detect Light or Dark color
Well, you could test based upon individual thresholds for red green and blue.
This page illustrates how to convert from RGB to HSB.
-
Mar 15th, 2006, 07:11 AM
#7
Re: Algo to detect Light or Dark color
Great !!! Thanks. 
I guess Luminance will do it. It will be easier to check.
btw, Lum and Brightness are same. Aren't they ?
-
Mar 15th, 2006, 07:12 AM
#8
Re: Algo to detect Light or Dark color
-
Mar 15th, 2006, 07:19 AM
#9
Re: Algo to detect Light or Dark color
Thanks !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|