0

We have a Grid component in WPF in which there are several Image components. Some of the Image components have an animation.

We want to save this produced animation as some consecutive BMP frames. Could you please give us a clue? Do Graphics Objects exist in WPF as in WindowsForms? If yes, how to access them?

Hamed
  • 1,175
  • 3
  • 20
  • 46

2 Answers2

1

You can save any WPF control to a file using RenderTargetBitmap like in the following snippet:

RenderTargetBitmap b = new RenderTargetBitmap(1000, 1000, 300, 300, PixelFormats.Pbgra32);

b.Render(controlToRender);

PngBitmapEncoder encoder = new PngBitmapEncoder();

encoder.Frames.Add(BitmapFrame.Create(b));

using (Stream s = File.Create(@"c:\test.png"))
    encoder.Save(s);
Alexander Mandt
  • 307
  • 1
  • 7
  • 10
0

There is a graphics class in WPF as in Windows Forms. The question of rendering control to an image was questioned multiple times. The best answer on how to do it, by my opinion, is this one WPF - Get size of UIElement in Memory?

You should also notice, that you have to wait until image is loaded, as described here RenderTargetBitmap does not render included images

And you may look at this question, if you would like to render the whole grid Save image of whole ListView

By combining these questions you should be able to make a snapshot of datagrid. And I believe you can try to use a DispatcherTimer to capture multiple images so the animation will be displayed in frames.

Community
  • 1
  • 1
netaholic
  • 1,345
  • 10
  • 22