ADC Home > Reference Library > Technical Q&As > Graphics & Imaging > Quartz >

Unexpected CG state changes


Q: Why does my Core Graphics drawing state change unexpectedly?

A: If you are using any of the convenience functions, such as CGContextFillRectWithWidth, be aware that they make use of the state variables and don't restore them. CGContextFillRectWithWidth, for example, clears the current path and changes the line width.

If you want to preserve the current settings, use CGContextSaveGState and CGContextRestoreGState. Note that even these APIs don't save the path. The only way to restore the path is to recreate it.


[Jul 02 2001]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.