Question

I've been searching for a way of casting inner glow (shadow) on NSImage. And I've landed on this topic. The code given under this topic looks promising. It's an unfamiliar territory for me now. Anyway, I'm stuck with the following line.

CGContextSetShadowWithColor(c,CGSizeMake(0,-1),innerShadowBlurRadius,CGColorGetConstantColor(kCGColorBlack));

More specifically, I don't quite understand the color part. According to the documentation, the last term is CGColorRef, which I have never used. I suppose it's the color type used for Quartz 2D drawing. In other words, specify a color in the language that Quartz 2D understands, maybe? Anyway, the documentation further suggests that there are three color constants. kCGColorWhite, kCGColorBlack, kCGColorClear. Does that mean I cannot specify an RGB color in this respect?

Thank you for your help.

Was it helpful?

Solution

No that's not what it means, and yes, you can specify RGB values; probably just not in the way you might be thinking. Quartz uses something known as CGColorSpaceRef, which you can think of as multidimensional — and each dimension represents a specific color component. An example would be the colors in the RGB color space, as three dimensions (red, green, and blue). The intensity of each component is represented by floating point values, and their range and meaning depends on the color space in question.

This should give you more concise information that you're looking for:

https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGColorSpace/Reference/reference.html#//apple_ref/doc/uid/TP30000949

Specifically take a look at:

CGColorCreateGenericRGB

Creates a color in the Generic RGB color space.

CGColorRef CGColorCreateGenericRGB(
   CGFloat red,
   CGFloat green,
   CGFloat blue,
   CGFloat alpha
);

and also the section on Constant Colors

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top