开发者

Pixelvalues turn up negative

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 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜