1

So here's my setup:

  • Camera images coming in at 1920x1080 @ 25 FPS
  • Writing image data to WriteableBitmap on UI thread (simple copy, no processing)
  • Two Image controls in two different windows on two different monitors has their Source property set to the WriteableBitmap
  • Some generic UI stuff goes over the camera images

This works great, uses about 4% CPU on an old laptop (8 logical processors). The video is as smooth as can be. However, my UI has some animations (stuff moving around). When the camera display is running, those animations gets choppy.

Right now, the camera image is in Gray8 format, so it will be converted (I guess when calling WritePixels?). I also tried forcing one of the animations to 25 FPS too, no change.

Where should I start to resolve this? Is the issue that I'm locking the bitmap for too long, or is there something else going on? From what I can see locking the bitmap will cause the render thread to block, so moving that to another thread seems pointless. And it does feel like that somewhat defeats the purpose of WriteableBitmap.

Chris
  • 5,442
  • 17
  • 30

1 Answers1

0

This is always going to be tricky because you're capturing at 25FPS whilst WPF tries to update at 60. It's difficult to offer any meaninful advice without seeing a testable project but I'd probably start by doing the updates in a CompositionTarget.Rendering handler.

Mark Feldman
  • 15,731
  • 3
  • 31
  • 58
  • Do you mean that I should do the animations manually in the `Rendering` event? I guess that would get them going at the same rate as the video. – Chris Sep 01 '15 at 07:02
  • No, I mean do your bitmap updates in the rendering handler. You know there'll be one render each time it's called, so updating your WriteableBitmaps in that function (at 25FPS, not every frame) might solve it. – Mark Feldman Sep 01 '15 at 07:26
  • Ah I see, that sounds reasonable. I'll give that a try. – Chris Sep 01 '15 at 07:31
  • I realize this is a couple of years old but I am in a similar situation and am wondering if this approach ended up working out for you -- or for any other advice you might have. In my case I'm trying to display at a higher framerate – Joe Dec 22 '17 at 19:06