• 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: UIColor vs. NSColor methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >UIColor vs. NSColor methods (From: Graham Cox <email@hidden>)
 >Re: UIColor vs. NSColor methods (From: Roland King <email@hidden>)

  • Prev by Date: Re: How to implement "while there are objects in the array - run runloop" idea?
  • Next by Date: How can logging a pointer value cause EXC_BAD_ACCESS?
  • Previous by thread: Re: UIColor vs. NSColor methods
  • Next by thread: Re: UIColor vs. NSColor methods
  • Index(es):
    • Date
    • Thread