CGContextSaveGStatecontext
CGContextSaveGState is a Core Graphics function that preserves the current state of a graphics context. The function takes one argument, a CGContextRef named context, and stores a snapshot of the context’s attributes in a stack. The saved state includes transformation matrices, clipping paths, alpha values, fill and stroke colors, line width, and other drawing parameters. When the function is invoked, the graphics context pushes the current state onto an internal stack, allowing subsequent drawing operations to modify the context without permanently altering the original configuration.
The paired function CGContextRestoreGState retrieves the previously saved state by popping the top entry from the
Usage of CGContextSaveGState is common in graphic rendering pipelines where temporary changes to the graphics context
The function is declared in the Core Graphics framework header CGContext.h and is available on macOS, iOS,
Relevant functions include CGContextSetStrokeColorWithColor, CGContextConcatCTM, and CGContextClipToRect, all of which modify the graphics context state that