我在 C# 中得到了反转的图像
这是我将 byte[] 数组转换为图像的代码
unsafe
{
//convert the UInt32[] into byte array and then assign the pointer to it
fixed (byte* ptr = Misc.ConvertFromUInt32Array(image))
{
Bitmap bmp = new Bitmap(200,64,800,
PixelFormat.Format32bppRgb,
new IntPtr(ptr));
bmp.Save("test.bmp");
}
}
我得到:
alt text http:////img11.imageshack.us/img11/4853/testacr.png
代码中的问题出在哪里,为什么会发生这种情况? 怎么翻转才能恢复正常呢?
this is my code to turn a byte[] array into an image
unsafe
{
//convert the UInt32[] into byte array and then assign the pointer to it
fixed (byte* ptr = Misc.ConvertFromUInt32Array(image))
{
Bitmap bmp = new Bitmap(200,64,800,
PixelFormat.Format32bppRgb,
new IntPtr(ptr));
bmp.Save("test.bmp");
}
}
And I get this:
alt text http:////img11.imageshack.us/img11/4853/testacr.png
Where's the problem in the code,why that happens? How to flip it back to normal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决了问题:)
Fixed the problem :)
嘿,看起来您发布的两张图片没有任何关系(除了具有类似的混淆模式)。 您是否发布了错误的文件?
关于您所看到的问题,我猜您遇到了 xy 轴原点的问题。 普通图像和图形 API 使用一个稍微奇怪的轴,您可以在 y 轴上“向下”计数,也就是说,点 (0, 0) 位于屏幕的左上角,当您递增 y 时,您会向下计数屏幕。 因此,假设您在转换中犯了错误或者两个图像使用不同的 y 轴方案似乎是合理的。
Hey it looks like the two images you posted are not related in any way (besides have a similar pattern of obfuscation). Did you post the wrong files?
With regard to the issue you are seeing, I would guess you are seeing a problem with the origin of the x-y axis. Normal images and graphics APIs use a slightly weird axis where you count "down" the y axis, that is to say, the point(0, 0) is at the top left of the screen and as you increment y, you go down the screen. Therefore it seems reasonable to assume that you have made a mistake in the conversion or that the two images are using a different y axis scheme.
为什么不将所有不安全的东西替换为:
Why not replace all that unsafe stuff with :