I want to save a writableimage in Silverlight to disk.
I found this tutorial : http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html, and have based my code on the EncodeJpeg method.
But at the:
pixelsForJpeg[0][x, y] = (byte)(color >> 16);
it throws an exception : Arithmetic operation resulted in an overflow.
At close inspection the color value is -16,777,216. The pixel is black and should have been 0.
When switching to a white pixel the value is -1.
I have tried to add 16,777,216 to see if there is some sort of offset, but this only works for black pixels, it crashes on a white one.
The pixel is indeed black. -16777216 is 0xFF000000. The FF is the Alpha channel.
What type are you using for color?
Also see this answer.