C # fast pixel rendering

I am developing depth processing (Xbox Kinect, Asus Xtion, etc.) using OpenNI.

I need a very simple and quick way to draw a Windows shape when new depth data is available from the sensor (30 or 60 frames per second depending on resolution).

Currently, I am invalidating a double-buffered panel from a separate stream when the data becomes available and then sets the pixels of the bitmap in the panel draw method, which gives a predictably terrible 5 frames per second.

System.Drawing.Graphics does not seem to have a quick way to set individual pixels, unless someone else can specify.

I just need to set the pixel colors, so if possible, avoid using third-party high-performance rendering APIs, and ideally use something as native as possible.

Does anyone have any suggestions?

+7
source share
3 answers

If you use bitmaps, you must use LockBits and UnlockBits to access data directly in memory. In C #, you can get extra performance by using unsafe code blocks and pointers.

See this link for more information: http://web.archive.org/web/20150227183132/http://bobpowell.net/lockingbits.aspx

+4
source

image.SetPixel() very slow when you replace a lot of pixels with a frame and you need a lot of frames per second.

It will be much faster if you use WriteableBitmap and call CopyPixels

This way you can populate the array with pixel data using multiple streams and simply split the array into an image at a time.

EDIT

Note that WriteableBitmap is a WPF class. If you are associated with WinForms, you may need to create your own implementation. WPF / WinForms / GDI interop: converting WriteableBitmap to System.Drawing.Image?

+4
source

You can try my LINQ image processing library to work with your "bitmap buffers." It uses a very accessible syntax, but is very effective for large bitmap images. It is available on Nuget , since your project includes one file.

Hope this helps!

0
source

All Articles