It looks like you have a performance leak. Here is what happens: you to accomplish some task with AForge.NET, but it requires different bit format, so you also convert to the 24-bit pixel format. I think your steps are quite reasonable, but you still get a bit less performance than requited by real-time video. Does it mean that you cannot improve performance (without resorting to native code)? I don't think so.
Here is what happens: you really do at least some of double work. Internally,
System.Drawing
does a number of things: it reads data, interprets it, put bits to canvas, something like that. And AForge.NET later does at least part of it again. Logically, the resolution would be to remove redundancy. Here are the ideas I have:
- Exclude reformatting pixels by looking at the source code of AForge.NET. Modify or update AForge.NET with the methods you use now, but working with your pixel formats. I means considerable job, but I'm sure it's quite possible. You just copy and slightly modify the code.
- You say that you just need to shift pixels. It sounds very simple. Most likely, you can work it out without using AForge.NET. You need to lock the pixels (specialized data pinning for pixels available in
System.Drawing
. Here is how:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits%28v=vs.110%29.aspx[^].
The MSDN articles on two methods referenced above comes with code samples which can help you to understand how to use them. You have two possibilities to improve performance by removing redundant processing:
a) you can have two bitmaps with different pixel format, to change pixel format of the target bitmap, but this time you can do your image transformation in the same "lock bit session", avoiding redundant marshaling of pixel back and forth, which should be a considerable overhear;
b) you can work with the same pixel format, as before, the 32-bit one; in this case, you can do all the transformation on the same set of bits, marshaling the image to data and data to image only once.
Please try. Good luck!
—SA