maharet313
maharet313

Reputation: 23

Can I get a CGColor from CGGradient?

I need to get a CGColor from a CGGradientRef, and use the color as a stroke colour in a drawing app for iOS 7. Is that possible?

Upvotes: 2

Views: 631

Answers (1)

Austin
Austin

Reputation: 5655

You could draw the gradient to an image context, get the pixel buffer for the image, then create a color from that pixel (see this post).

Otherwise, CGGradientRef is an opaque type, and there isn't any way to get information out of it. For my own apps, I've also created a wrapper object around CGGradientRef that creates the gradient and stores the colors / locations it was created with.

Upvotes: 1

Related Questions