Home All Groups Group Topic Archive Search About

Is there a way to save the whole graphic state in WPF?

Author
18 Oct 2007 4:57 PM
HappyGilmore
Consider the following pseudocode. What I want to do is save the complete
graphic state at the beginning of a function and then restore it back at the
end of the function call. In GDI+ there are functions Save() and Restore(),
which I’m using right now to achieve the following functionality. Now we are
migrating the application to WPF but the problem I’m facing is that there is
no function that returns the complete graphics state. In DrawingContext,
there are functions e.g. (PushClip, PushTransform, etc.) which pushes
individual graphic state but I want to take snapshoot of current graphics
state and then restore it back.
Foo()
{
// Take a snapshot of current graphics state and save it on a stack
SaveGraphicsState();   
// change the graphics state by applying clipping or any other transformations
Bar()
DrawSomeLine()
// Restore the previous graphics state by popping the stack
RestoreGraphicsState();
}
Bar()
{
SaveGraphicsState();
Rotate(30);
DrawRectangle
Bar2();
RestoreGraphicsState()
}
Bar2()
{
SaveGraphicsState();
RestoreGraphicsState()
}

AddThis Social Bookmark Button