How is Graphics.Save
different from Graphics.BeginContainer
?
take a look here:
The documentation does not differentiate between calls to BeginContainer/EndContainer and calls to Graphics.Save and GraphicsRestore. In addition, there are a few errors in the documentation. [e.g., GraphicsState is incorrectly asserted to be used by BeginContainer]
In my use, BeginContainer/EndContainer appears to save and restore the current transform. It does not actually save the clipping region as the documentation asserts, and it may not save any of the other properties in the graphics objects.
With Save/Restore, I was actually able to save/restore the clipping region, current transform, and other settings. It appears to be, if not complete, more "complete" than the container functions. Therefore, I suspect a performance/completeness tradeoff with the two different methods.
I also doubt whether the documentation is correct in stating that GraphicsState objects (used by Save) are stored in the stack as are GraphicsContainer objects (used by BeginContainer). I suspect that GraphicsState may not even be placed on a stack, but I have not tested this hypothesis.
Maybe I can give a explanation from some examples of MSDN. The version of my MSDN is Visual Studio 2008 SP1. And the examples can be found when you enter the keyword "Nested Graphics Containers" in the edit of MSDN.
And its explanation is below:
As the two preceding examples show, transformations and clipping regions are cumulative in nested containers. If you set the world transformations of the container and the Graphics object, both transformations will apply to items drawn from inside the container. The transformation of the container will be applied first, and the transformation of the Graphics object will be applied second. If you set the clipping regions of the container and the Graphics object, items drawn from inside the container will be clipped by the intersection of the two clipping regions.
From the content copied above, the keywords are "cumulative" and "intersection". Therefore, I think it can be a way to understand the BeginContainer function.
Full MSDN article available here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With