Re: Deciding whether text should be black or white for a given background color
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