Are your coordinates (x0
, y0
, x1
, y1
, etc.) at integer point values? It's common for people to make that mistake because they're used to setting views' frames to be on whole point boundaries. CoreGraphics draws with one point lines drawn centered on the coordinates you provide. I suspect that you can eliminate your artifacts by adjusting your coordinates by 0.5 points in all cases:
CGContextBeginPath(context);
CGContextMoveToPoint(context, x0 + 0.5, y0 + 0.5);
CGContextAddLineToPoint(context, x1 + 0.5, y1 + 0.5);
CGContextAddLineToPoint(context, x2 + 0.5, y2 + 0.5);
CGContextClosePath(context);
CGContextFillPath(context);
Edit: Actually I don't think this is going to work. Here's another suggestion:
I'm leaving my previous comments because I think what I said about the CoreGraphics coordinates is true, but I tried some experiments with the setup you described and shifting everything over didn't eliminate those border artifacts. However adding this line did:
CGContextSetAllowsAntialiasing(context, false);
(I don't know why CGContextSetAllowsAntialiasing
is declared to take a stdbool style bool, but it is, that's why I used false
instead of NO
here, not that it makes a difference.)