4
votes

I'm a bit confused by the coordinate system differences between UIKit and Core Graphics. The Apple documentation notes that UIKit uses an ULO (Upper Left Origin) while Core Graphics uses a LLO (Lower Left Origin).

However, as noted in a post about coordinate systems, it is noted that UIKit

helpfully flips the coordinate system before calling -drawRect:

When I draw a rectangle at (0,0), it is indeed in the upper left hand corner, so things do seem flipped. However, when I draw an image using CGContextDrawImage(), it is still flipped. I understand I can just use drawAtPoint() to avoid the upside down image, but I am just curious about the coordinate system: if it's flipped by UIKit, why is the image still upside down if it is drawn into the flipped context? Also, is there any way to get an unflipped coordinate system? That is, is there a way to create a CGContext without going through the UIKit?

Thanks!

1

1 Answers

1
votes

Since I've gotten no answers, I'll present my best guess: UIKit "helpfully" flips the context from LLO to ULO but, unlike a path, an image has its own coordinate system internally (for the image). In Core Graphics, this coordinate system is interpreted as LLO and so it's upside down.

As for creating a CGContext without UIKit - it seems like it used to be possible back in the day but has been removed.

Any comments/corrections appreciated.