When we do:
CGContextRef ctx = UIGraphicsGetCurrentContext();
what exactly is ctx? Apparently it's a struct. Where is the struct defined? What are its members?
When we do:
CGContextRef ctx = UIGraphicsGetCurrentContext();
what exactly is ctx? Apparently it's a struct. Where is the struct defined? What are its members?
It is a pointer to a struct. The struct is opaque. Just use the functions connected with it.
What is a graphics context?
A graphics context refers to the graphic destination. Destination can be a window in an application, a bitmap image, a PDF document, or a printer.
If you want to draw on a view, the view is your graphicsContext or if you wish to draw on an image then that image becomes your graphicsContext.
So, if you wish to make custom drawing using CoreGraphics , you must get the graphic context (destination where you want to put your drawing) . After getting the context , drawing can be done using the CoreGraphics function. Almost all CoreGraphics function has a parameter context. So, each time we call the coregraphics function we first get the current context and pass it as a parameter.
How can you obtain a graphics context?
You can obtain a graphics context by using Quartz graphics context creation functions or by using higher-level functions provided in the Carbon, Cocoa, or Printing frameworks. For eg: Quartz provides creation functions for various flavors of Quartz graphics contexts including bitmap images and PDF. The Cocoa framework provides functions for obtaining window graphics contexts. The Printing framework provides functions that obtain a graphics context appropriate for the destination printer.
What a graphics context contains?
It contains drawing parameters and all device-specific information needed to render the paint to the destination.
Source:: https://developer.apple.com/library/ios/documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_layers/dq_layers.html