What is a fast way to generate and draw video in WPF?

别等时光非礼了梦想. 提交于 2019-11-30 15:28:26

If I understand correctly you receive a 16*16 pixel block as a capture, and in the example above you are then updating the writeable bitmap on each of these updates.

This looks like a lot of churn as a render is being triggered on each block.

Would it not be better to:

  • Maintain a single byte buffer that represents an entire frame.
  • Update the buffer with your 16*16 blocks as you receive them.
  • When you have received all blocks for a frame, write the buffer to the bitmap.
  • Re-use the frame buffer for the next frame by over-writing it.

In this way you will have far less churn on rendering as you will not trigger a render for each block you receive, but only for each frame.

Update 1

I would also consider using Bgr24 as your pixel format if you are not using an alpha channel. That way you will have 3 bytes per pixel, instead of 4, so quite a lot less overhead.

Update 2

If things are still too slow for larger frame sizes, you could also consider the following which adds complexity though.

Consider maintaining and flipping two frame buffers. In this way you could composite frames on a background thread and then blit the finished frame on the UI thread. Whist the UI thread is rendering the frame, you can continue compositing on the alternative buffer.

Update 3

If your pixel colour info array from your capture is in the correct format, you could try using Buffer.BlockCopy to bulk copy the source pixel array into the frame buffer array. You would have to keep your bitmap format as bgr32 though. This low level array copying technique could yield some performance gains.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!