This project is read-only.

Parallel CustomBitmap CopyPixels

Mar 8, 2011 at 4:15 PM

Ok, so  I have been using the CustomBitmap class for a custom movie format player.  My question is if there is a way to call CopyPixels only once per frame  instead of once per row.  I have mirrored the basic architecture of CustomBitmap for use in Windows Forms using the PictureBox and Bitmap classes, and I can write parallel code there because I can control when the CopyPixels method is called (once per set of PictureBox.Image).  This does not appear to be the case in Wpf using the Image control, my breakpoint in the CopyPixels method is hit for each row in the image, disallowing any sort of parallel bit copying (copying multiple row bits concurrently).  Is there a flag on the Image control I need to set?

Mar 11, 2011 at 5:31 PM

Interesting!  I was not aware that CopyPixels was called per row.  That seems odd.  Anyways, there are probably better options for WPF:

1) Use D3DImage to render a DX surface.

2) Create an InteropBitmap around a shared memory surface, write to the shared memory yourself, and call InteropBitmap.Invalidate() when the content changes.

3) Use WriteableBitmap, which is a little slower due to the overhead of system-memory copies.

Mar 14, 2011 at 4:01 PM

Thanks for the alternative suggestions.  CustomBitmap was the first thing I found that seemed to be possible for what I needed.  I'll take a look at some of those others.

Mar 14, 2011 at 4:05 PM

On my other thread about the memory leak, the repro example also repro's the per row call, which is why I added a row counter to my version of the CustomBitmapBase class.  I did not expect it either from looking at your code and would not have found it if I weren't trying to use Parallel for loops inside of CopyPixelsCore.