3
votes

I have a project where i need to perform fast image rendering.

Currently, i use image control with stretch disabled. update is made by timer, by setting Source property.

WriteableBitmap frame = Player.Get().GetFrame();
if (frame != null)
     image.Source = frame;

This part become a performance bottleneck. More clearly image.Source = frame is a bottleneck.

I looked at MediaElement, but it's not applicable.

Is there any ways to perform it faster?

Maybe some method as in GDI BitBlt or similar?

Thanks in advance.

2
Is the bottleneck Player.Get().GetFrame(), or image.Source = frame?Brandon Dybala
Bottleneck really in image.Source = frame. It was working fast in WinForms, but when i ported in to WPF, performance greatly decreased.Андрей Москвичёв
Maybe the writeablebitmapex.codeplex.com project has some tricks?Govert
Does it make a difference if you keep a single WriteableBitmap, and set its Pixels with every frame?Govert
For now it's implemented such way. It use single WriteableBitmap, and Source = frame is used to redraw Image element. I didn't found another way to redraw Image element.Андрей Москвичёв

2 Answers

1
votes

You won't get much performance out of WPF. Even MediaElement can't handle HD videos correctly, without flickering and lagging.

Host a WinForms element in your WPF application using WindowsFormsHost tag and do the blitting there if you want to use GDI. Though GDI is mostly software based, you might want to check out DirectX or GDI+.

1
votes

If you really need the performance, your best bet is probably to write a small wrapper for bitblt.

Perhaps those two articles help you:

BitBlt Dot Net Style

Using BitBlt to copy and paste graphics