Re: NSColor to CGColor
Re: NSColor to CGColor
- Subject: Re: NSColor to CGColor
- From: j o a r <email@hidden>
- Date: Sun, 12 Nov 2006 16:48:30 +0100
On 12 nov 2006, at 16.32, Antonio Nunes wrote:
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?
I also bumped into this problem recently and ended up implementing
this function:
static CGColorRef CGColorCreateFromNSColor (CGColorSpaceRef
colorSpace, NSColor *color)
{
NSColor *deviceColor = [color colorUsingColorSpaceName:
NSDeviceRGBColorSpace];
float components[4];
[deviceColor getRed: &components[0] green: &components[1] blue:
&components[2] alpha: &components[3]];
return CGColorCreate (colorSpace, components);
}
That I call like this:
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB ();
CGColorRef cgColor = CGColorCreateFromNSColor (colorSpace, nsColor);
CGColorSpaceRelease (colorSpace);
// Do stuff with cgColor
CGColorRelease (cgColor);
j o a r
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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