Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Masking CGContext with a CGPathRef?

I am doing some drawing using a CGContext. I am currently masking the drawing using a png file like this:

UIImage * myImage = [UIImage imageNamed:@"frame.png"];
CGContextRef context = UIGraphicsGetCurrentContext ();
CGContextClipToMask(context, self.view.bounds, myImage.CGImage);

This works fine, but now I'd like to use an existing CGPathRef as my mask. Should I look at converting the CGPathRef to a UIImage and mask as above? If so how would I go about doing the conversion? -OR- Is there a better way to approach this?

like image 840
Frank Avatar asked Feb 29 '12 16:02

Frank


1 Answers

CGContextAddPath(context, yourPath);
CGContextClip(context);
like image 179
cxa Avatar answered Sep 18 '22 14:09

cxa