by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 2/27/2007 7:10:00 PM
I've been playing around with WPF animation, and ended up wanting to take a snapshot of an animation at a specific place.
Specifically, I have a canvas that has some pictures on it that are moving, and I want to be able to save a bitmap of what it looks like at a specific time.
Getting the bitmap is pretty easy, using a RenderTargetBitmap and a VisualBrush.
private BitmapSource CaptureScreen(Visual target){
Rect bounds = VisualTreeHelper.GetDescendantBounds(target);
ctx.DrawRectangle(vb,
That gives you the state of the objects pre-animation, but what I really wanted was the state of the objects during the animation. I had some code to move the image around:
DoubleAnimation
After a bit of research, I settled on the following bit of code to set the animation to the point that I wanted:
clock.Controller.SeekAlignedToLastTick(
Which should have worked fine, but didn't. When I looked at the properties, I noticed that the Left property was changing, but it wasn't showing up. It was almost as if the Canvas didn't know that the object property had changed and a re-layout was necessary...
m_canvas.UpdateLayout();
was the magic incantation to make that happen.
(Note that I'm a novice at WPF, and there may be a better way to do this...)
Original Post: Taking snapshots of WPF animation
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.