Results 1 to 9 of 9

Thread: [RESOLVED] Algo to detect Light or Dark color

  1. #1

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Resolved [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 ?
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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

  5. #5

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  7. #7

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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 ?
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Algo to detect Light or Dark color

    One and, yes.

  9. #9

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Algo to detect Light or Dark color

    Thanks !
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width