C#Texture2D SetData ARGB?

时间:2011-05-21 21:03:21

标签: c# xna

我正在尝试从Bitmap制作Texture2D。我有

Texture2D BitmapToTexture(Bitmap img)
{
    var ret = new Texture2D(Game.GraphicsDevice, img.Width, img.Height);
    var bd = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
    int[] bytes = new int[img.Width * img.Height];
    Marshal.Copy(bd.Scan0, bytes, 0, bytes.Length);
    ret.SetData(bytes);
    img.UnlockBits(bd);
    return ret;
}

问题是SetData出于某种原因期待ABGR。有没有办法获得SetData  采取ARGB数据?

1 个答案:

答案 0 :(得分:2)

不幸的是没有。你必须自己交换字节。

字节顺序为changed in XNA 4.0 (see last paragraph)

另见this answer