Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the coordinate system in an CGContextRef look like?

I assume that the origin is on the bottom left, and the y-axis expands up, starting from 0. The x-axis expands to the right, starting from 0.

I just ask because I get very weird results from my drawing code... want to make sure that I didn't get this part wrong.

like image 626
Thanks Avatar asked Dec 07 '22 07:12

Thanks


1 Answers

It depends on where this context is being used. The standard Core Graphics drawing context used on the Mac for view, layer, and image drawing has (0,0) for its bottom left coordinate.

The standard coordinate system on the iPhone is inverted, with the upper left coordinate for a UIView being (0,0). Its backing layer also has those flipped coordinates, so drawing into a context for the view or its layer starts at (0,0) for the upper left. UIImage contexts are also flipped in this manner, but PDF contexts are not.

All of this is documented in various locations within Apple's iPhone programming guides, but it can be a bit confusing to sort out.

like image 72
Brad Larson Avatar answered Dec 09 '22 20:12

Brad Larson