Saturday 21 March 2009

Silverlight: WriteableBitmap Gotchas

So I updated my Silverlight Spectrum Emulator to work with Silverlight 3 and in this process I used the new WriteableBitmap class.

I just wanted to make you aware of a few gotchas that I experienced whilst working with this.

Set the Image Source everytime

Gotcha number 1, for some reason after updating a bitmap, you must reset the source of the image to your bitmap.  If you don't then you will get very jerky updates (it won't re-render every time).

Out of Memory Exceptions

Due to gotcha number 1, you may be tempted touse a local variable for the WriteableBitmap, and then set the source of the image.  DO NOT do this, as it will steal all your memory, and you will get an out of memory exception.

To get around this you should scope your WriteableBitmap to your page, and thus you will avoid the out of memory exception

No comments: