像素值变为负值
我想将 Silverlight 中的可写图像保存到磁盘。
我找到了这个教程: http://kodierer.blogspot .com/2009/11/convert-encode-and-decode-silverlight.html,并且我的代码基于 EncodeJpeg 方法。
但在:
pixelsForJpeg[0][x, y] = (byte)(color >> 16);
它抛出异常:算术运算导致溢出。 仔细观察,颜色值为-16,777,216。像素是黑色的,应该是 0。 当切换到白色像素时,该值为-1。
我尝试添加 16,777,216 来查看是否存在某种偏移,但这仅适用于黑色像素,它会在白色像素上崩溃。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该像素确实是黑色的。 -16777216 是 0xFF000000。 FF 是 Alpha 通道。
您使用什么类型的颜色?
另请参阅此答案。
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.
听起来像是一个带符号的整数值。所有位均设置的有符号整数值为负数。例如,如果有符号,0xFFFF 表示设置了 16 位,高位表示低 15 位描述负值。
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.