2

这是我将 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");
  }
}

我明白了:

替代文字 http://img11.imageshack.us/img11/4853/testacr.png

代码中的问题在哪里,为什么会发生这种情况?怎样才能让它恢复正常?

4

3 回答 3

8
   bmp.RotateFlip(RotateFlipType.Rotate180FlipX);

修复了问题:)

于 2009-04-13T04:42:35.840 回答
1

嘿,看起来你发布的两张图片没有任何关系(除了有类似的混淆模式)。你发错文件了吗?

关于您看到的问题,我猜您看到的是 xy 轴原点的问题。普通图像和图形 API 使用一个稍微奇怪的轴,您在 y 轴“向下”计数,也就是说,point(0, 0) 位于屏幕的左上角,当您增加 y 时,您向下计数屏幕。因此,假设您在转换中犯了错误或这两个图像使用不同的 y 轴方案似乎是合理的。

于 2009-04-13T04:31:27.130 回答
1

为什么不将所有不安全的东西替换为:

private static Bitmap ConvertFromBytes(Byte[] imagebytes)
{
   return new Bitmap(new MemoryStream(imagebytes));
}
于 2009-04-13T04:52:34.880 回答