• 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 14:05:28 -0500

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]));
_______________________________________________

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: Ricky Sharp <email@hidden>
  • Prev by Date: Re: CFMessagePort problems
  • Next by Date: Re: CFMessagePort problems
  • 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