• 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: Gregory Weston <email@hidden>
  • Date: Mon, 4 Dec 2006 16:59:26 -0500


On Dec 4, 2006, at 4:10 PM, Ricky Sharp wrote:

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.

I probably should have clarified my intent in pointing that out to the OP. My thought was that he could use that to determine the grey level of the background and then arbitrarily pick some level at which he should switch from black text to white.


Greg
_______________________________________________

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


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

  • Prev by Date: Re: Synchronizing Thread Execution
  • Next by Date: Re: Cocoa class for expanding .zip files
  • 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