How to render WPF animation as a video frame by fr

2019-03-31 03:06发布

问题:

I've created a nice effect that I like in WPF, I'd like to be able to "record" this effect. But it is choppy during run-time.

Is there a way I can convert it to a frame-by-frame process and save it as a video myself instead of trying to record it during playback?

Basically I'd like to render WPF as a video, or list a series of frames saved as bitmaps.

Key thing is to be able to record the animation with out the choppiness.

回答1:

Have you looked at using RenderTargetBitmap to render your Visual as a bitmap? You might have to play with the animation's timing or hook into the OnRender event, but that will let you capture your control as an image.

To expand on the animation's timing bit: If you want to render your animation and save it as bitmaps (to then make a video), you might be able to use a Clock's ClockController to manually advance the animation and render each frame to file.

Another alternative is to set the To, From, and By to values that let you render each frame (e.g. if the animation takes one second, and you want to make a 30 fps video, you could worst case alter the animation to take 30 seconds, advance by one second, and render to bitmap after each advance).