Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 522
prostock Avatar asked Mar 31 '11 01:03

prostock


1 Answers

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.

like image 83
Peter Hosey Avatar answered Sep 19 '22 18:09

Peter Hosey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!