Possible Duplicate:
drawing UIImage inside a CGMutablePath
I have a path in my drawRect that looks like this:
CGContextSetLineWidth(context, 1.5);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context);
CGContextClip(context);
CGContextTranslateCTM(context, 0.0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, self.image_.CGImage);
UIGraphicsBeginImageContext(rect.size);
UIImage * circleUserProfile = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[circleUserProfile drawAtPoint:CGPointMake(0, 0)];
CGContextRestoreGState(context);
and I have a UIImage, and I want so that the UIImage to clip inside this circle. The code above seemed to be doing what I asked before here, but still doesn’t work. Why is this?
When you call
UIGraphicsBeginImageContext, you’re creating a new context, pushing your previous one (that you did all your drawing in), and making the new (empty) one the current context. You need to begin your image context prior to callingUIGraphicsGetCurrentContextand performing your drawing.