I am trying to use CGContextClip() to do some drawing, however I am running into some weird antialiasing problems. The problem appears to be that that the filling is being blended with the colour that it is replacing, instead of the surrounding pixels. See images for a slightly better description of the problem!
Example of issue:
(Note that the blue edge is being antialiased correctly)
Weird antialiased edge:
(Edge should be blended with white, not blue)
Code:
-(void) drawRect:(CGRect)rect {
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSaveGState(c);
{
CGContextBeginPath(c);
CGContextAddEllipseInRect(c, CGRectMake(25, 25, 200, 200));
CGContextClosePath(c);
CGContextClip(c);
CGContextSetFillColorWithColor(c, [UIColor blueColor].CGColor);
CGContextFillRect(c, rect);
CGContextSetFillColorWithColor(c, [UIColor redColor].CGColor);
CGContextFillRect(c, CGRectMake(0, 0, 250, 125));
}
CGContextRestoreGState(c);
}
Any ideas on how to prevent this weird antialiasing? I can't disable it, as the circle edges still need antialiasing!
Just to be clear, this is simply an example. I am trying to solve this issue on a much more complicated shape, where the solution of only filling half of the clipping to begin with simply isn't possible!