• 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: NSColor to CGColor
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSColor to CGColor


  • Subject: Re: NSColor to CGColor
  • From: Daniel Jalkut <email@hidden>
  • Date: Sun, 12 Nov 2006 10:56:50 -0500

On Nov 12, 2006, at 10:32 AM, Antonio Nunes wrote:
Hi,

Couldn't find any pointers in the Apple docs (other than that the two types appear not to be toll-free bridged), and amazingly searching in cocoabuilder on "CGColor" yields no results at all. Nada. So no info on converting an NSColor to a CGColor. Googling for these two words yields no usable results either, so hence the question here: What is the best/easiest way to convert an NSColor to a CGColor?

Thanks,
António


When I've had to do this I've just init'ed a new CGColor based on the components of the NSColor. Something like:

NSColor* someNSColor = [NSColor redColor];
CGColorRef someCGColor = NULL;
CGColorSpaceRef genericRGBSpace = CGColorSpaceCreateWithName (kCGColorSpaceGenericRGB);
if (genericRGBSpace != NULL)
{
float colorComponents[4] = = {[someNSColor redComponent], [someNSColor greenComponent], [someNSColor blueComponent], [someNSColor alphaComponent]};
someCGColor = CGColorCreate(genericRGBSpace, colorComponents);
CGColorSpaceRelease(genericRGBSpace);
}
// got someCGColor? have fun...


Apply colorspace finickiness as necessary...

Daniel

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSColor to CGColor (From: Antonio Nunes <email@hidden>)

  • Prev by Date: Re: NSColor to CGColor
  • Next by Date: Re: NSColor to CGColor
  • Previous by thread: Re: NSColor to CGColor
  • Next by thread: Installing carbon event handlers into a cocoa application
  • Index(es):
    • Date
    • Thread