• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Deciding whether text should be black or white for a given background color
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Deciding whether text should be black or white for a given background color


  • Subject: Re: Deciding whether text should be black or white for a given background color
  • From: Ricky Sharp <email@hidden>
  • Date: Mon, 04 Dec 2006 13:10:45 -0800

On Monday, December 04, 2006, at 01:06PM, "Gregory Weston" <email@hidden> wrote:
>On Dec 4, 2006, at 1:57 PM, Keith Blount wrote:
>
>> The problem is, how do I programmatically decide what is a light-
>> and what is a dark-coloured background using methods available to
>> NSColor? Is there a well-known algorithm for deciding this?
>
>You might try the math used in this sample code as a starting point.
>
><http://developer.apple.com/samplecode/Monochrome_Image/index.html>
>
>The most interesting line for you, I'd think, is from
>NSImage_monochrome.m
>
>thisPixel->grayValue = rint(255 *
>                   (0.299 * [pixelColor redComponent]
>                  + 0.587 * [pixelColor greenComponent]
>                  + 0.114 * [pixelColor blueComponent]));

This is the NTSC weighted algorithm.  I know it works very well (use it in my own app for grayscale conversions).  Not sure how it will stack up for the original poster's problem, but it's definitely worth a shot to compare such results with the standard brightness computation.

--
Rick Sharp
Instant Interactive(tm)

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Deciding whether text should be black or white for a given background color
      • From: Gregory Weston <email@hidden>
References: 
 >Re: Deciding whether text should be black or white for a given background color (From: Gregory Weston <email@hidden>)

  • Prev by Date: Fwd: Window menu not displaying open windows?
  • Next by Date: Text Caret -- Focus Ring Interference
  • Previous by thread: Re: Deciding whether text should be black or white for a given background color
  • Next by thread: Re: Deciding whether text should be black or white for a given background color
  • Index(es):
    • Date
    • Thread