这是我将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
代码中的问题在哪里,为什么会这样?如何将其恢复正常?
答案 0 :(得分:7)
bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
解决了问题:)
答案 1 :(得分:1)
嘿,看起来你发布的两张图片没有任何关联(除了有类似的混淆模式)。你发错了文件了吗?
关于你所看到的问题,我猜你会发现x-y轴的原点出现问题。普通图像和图形API使用一个稍微怪异的轴,你在y轴上“向下”计数,也就是说,点(0,0)位于屏幕的左上角,当你增加y时,你会下降屏幕。因此,假设您在转换中出错或者两个图像使用不同的y轴方案似乎是合理的。
答案 2 :(得分:1)
为什么不用以下内容替换所有不安全的东西:
private static Bitmap ConvertFromBytes(Byte[] imagebytes)
{
return new Bitmap(new MemoryStream(imagebytes));
}