prostock
prostock

Reputation: 9545

What is the purpose of CGContextSaveGState and CGContextRestoreGState?

I see a lot of sample code where they use CGContextSaveGState and CGContextRestoreGState. Why would I need to save the state of the context?

Upvotes: 19

Views: 11419

Answers (1)

Peter Hosey
Peter Hosey

Reputation: 96333

In order to restore it later.

Some of the things you can change about a context are difficult (e.g., CTM) or impossible (e.g., clipping path) to change back. Saving the gstate lets you undo those changes by restoring the gstate.

The Quartz 2D Programming Guide tells all.

Upvotes: 21

Related Questions