So when drawing a custom-Cocoa-control, I had an issue where an NSImage
(bitmap) and an NSBezierPath
(vector-shape) didn’t move in sync with each other.
Using floor()
to force all pixel-coordinate to be a whole number fixed the problem. There is probably a much better solution — after-all this was the first custom-control I have ever done in Cocoa. But when a simple solution works…
UPDATED: 2009-05-25: @cocoadevcentral tweets,
NSIntegralRect()
andCGRectIntegral()
take a rect and return a copy which is aligned to integer coordinates. Good to avoid blurriness.
They sound like a better solution then calling floor()
on each element of an image.