1

So, I have a Winforms control that is an ElementHost of a WPF control. This WPF control houses several different UIElements that renders GIS data (vector and raster). What I'd like to do is record the user's activity and any animations (like vehicle position). None of the following methods work for me because they are either too slow or have limitations.

Method 1: DrawToBitmap

In previous iterations, the control was in pure Winforms. I could just call the Winforms DrawToBitmap method and get an image in about 10ms. But now that I'm using an ElementHost, getting an image in about 80ms. I have a feeling that behind the scenes, this method is using the RenderTargetBitmap method.

Method 2: RenderTargetBitmap

Alternatively, I tried using RenderTargetBitmap, passing in the canvas from the WPF control to create a bitmap image. But this also takes about 80ms to complete.

Method 3: System.Drawing CopyFromScreen

Doing a screen capture this way works. I can get images in about 35ms. But if a separate window gets in the way during recording or something of that matter, then the recording sees it too.

My Question

Is there a way to record a control that is faster than RenderTargetBitmap without the downside of CopyFromScreen? Is it possible to get in front of the RenderContext found in the OnRender of a control and create an image from that? Or maybe there is some other way that I'm not thinking of?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
tg_kyle
  • 81
  • 5
  • I would suggest doing more detailed performance profiling on these options and making sure you are informed on exactly *why* those methods take as long as they do. – Romen Jun 30 '22 at 19:20
  • 2
    Try `PrintWindow` (an example here: [Print an image of the content of a Panel excluding any external overlapping Window](https://stackoverflow.com/a/68895127/7444103)) -- Note that I don't remember whether it works as intended with an ElementHost (or how much time it takes, for that matter). Might be worth a test run. – Jimi Jun 30 '22 at 19:36
  • @Jimi I think you got it. I set it up like in that post and it looks like I'm getting images in about 15ms. If you can create this as answer, I'll mark it as answered. – tg_kyle Jul 06 '22 at 22:01

0 Answers0