views:

45

answers:

2

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.

+4  A: 

The pixel is black and should have been 0

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.

Jonas Elfström
A: 

Sounds like a signed integer value that wraps over. A signed integer value with all bits set is negative. For instance, 0xFFFF if signed means that 16 bits are set and the high bit indicates that the lower 15 bits describe a negative value.

Johann Gerell