rendering on a background thread

Jul 21, 2010 at 2:44 PM
Edited Jul 21, 2010 at 2:45 PM

Hi there!

To gain performance I would like to render to bitmap on a background thread while only moving around those bitmaps on the UI Thread. Creating WriteableBitmap on a background thread results in an cross thread exception right away because this is not allowed in Silverlight. In WPF this can be prevented by working with a STA thread. Do you see ways this library could be used for rendering on a background thread?

Thanks in advance.


Jul 21, 2010 at 3:06 PM
Edited Jul 21, 2010 at 3:07 PM

Hi Paul,

I know what you mean. The possible solution would be to only use the int[] array in the backround threads and copy this data at the end of the process to a WriteableBitmap in the UI thread. I created an issue for this a while ago: Overloads for int[] pixels But I had no time to implement it until now and this won't change anytime soon. Feel free to vote the issue up. Contributions are also always welcome. :)

- René

Jul 21, 2010 at 3:25 PM

hi Rene,

Thanks for your fast reply.

How hard would this be to implement. Superficially it looks like a straight forward problem that could be done by someone without much knowledge of the code. Or could I also run into trickier problems?


Jul 21, 2010 at 5:57 PM

It should be a pretty easy task.

I actually done this already for the DrawLine method. See these two methods:

public static void DrawLine(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color)
   DrawLine(bmp.Pixels, bmp.PixelWidth, bmp.PixelHeight, x1, y1, x2, y2, color);

public static void DrawLine(int[] pixels, int pixelWidth, int pixelHeight, int x1, int y1, int x2, int y2, int color)
   // ...