Can I get a CGColor from CGGradient?

626 views Asked by At

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?

1

There are 1 answers

0
Austin On BEST ANSWER

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.