< Previous PageNext Page > Hide TOC

Accessing a Color’s Components

There’s usually no need to retrieve the individual components of a color, but when needed, you can retrieve either a set of components (using such methods as getRed:green:blue:alpha:) or an individual component (using such methods as redComponent). However, it’s illegal to ask an NSColor for components that aren’t defined for its color space. You can identify the color space by sending a colorSpaceName message to the NSColor object. If you need to ask an NSColor for components that aren’t in its color space (for instance, when you’ve gotten the color from the color panel), first convert the color to the appropriate color space using the colorUsingColorSpaceName: method. If the color is already in the specified color space, you get the same color back; otherwise you get a conversion that’s usually lossy or that’s correct only for the current device. You get back nil if the specified conversion can’t be done.



< Previous PageNext Page > Hide TOC


© 2005, 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-03-04)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.