Re: UIColor vs. NSColor methods
Re: UIColor vs. NSColor methods
- Subject: Re: UIColor vs. NSColor methods
- From: Kyle Sluder <email@hidden>
- Date: Sun, 29 May 2011 10:02:38 -0700
On Sat, May 28, 2011 at 10:50 PM, Roland King <email@hidden> wrote:
> You can use CGColorGetComponents on a CGColorRef to get the values of whatever colorspace the CGColorRef is in and you can create new CGColorRefs with those values.
>
> I don't see a way to convert from one colorspace to another however a quick test on one UIColor constructed with HSV values shows its contained CGColorRef to have an RGB colorspace which you could get the RGB values from. Whether you can rely on that I don't know and haven't found any documentation to back it up.
The only real way to convert between color spaces is to render the
color in a bitmap context that has the desired destination color
space.
Unfortunately there are very few color spaces available on iOS. The
color space name constants are not available, and there are no
device-independent color spaces.
The correct way to do what Graham is doing would require a
perceptually linear color space like Lab. Otherwise shifting hue from
blue to green, for example, would greatly increase the perceived
intensity of the color. Unfortunately, there's no predefined Lab color
space available; you have to provide tristimulus values yourself for
the black and white points.
There is a fair bit of code in OmniQuartz.framework's OQColor.h [1],
but sadly we haven't removed all the stuff that shouldn't be used. To
convert from one color space to another, you would want to use
OQCreateCompositeColorFromColors, which draws the provided array of
CGColorRefs into a 1-pixel CGBitmapContext in the desired color space.
For a simple colorspace conversion, just pass a 1-element array.
[1] https://github.com/omnigroup/OmniGroup/blob/master/Frameworks/OmniQuartz/OQColor.h
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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