开发者

C# Texture2D SetData ARGB?

开发者 https://www.devze.com 2023-03-07 06:51 出处:网络
I am trying to make a Texture2D from a Bitmap. I have Texture2D BitmapToTexture(Bitmap img) { var ret = new Texture2D(Game.GraphicsDevice, img.Width, img.Height);

I am trying to make a Texture2D from a Bitmap. I have

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;
}

The issue is that SetData is for some reason expec开发者_如何学编程ting ABGR. Is there a way to get SetData to take ARGB data?


Unfortunately not. You have to swap the bytes yourself.

The byte ordering was changed in XNA 4.0 (see last paragraph).

See also this answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号