Re: NSColor to CGColor
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