Bitmap to Texture2D problem with colors

Posted by xnaNewbie89 on Game Development See other posts from Game Development or by xnaNewbie89
Published on 2010-12-12T02:47:03Z Indexed on 2012/06/26 9:23 UTC
Read the original article Hit count: 335

Filed under:
|
|

I have a small problem with converting a bitmap to a Texture2D. The resulted image of the conversion has the red channel switched with the blue channel :/ I don't know why, because the pixel formats are the same. If someone can help me I will be very happy :)

      System.Drawing.Image image = 
            System.Drawing.Bitmap.FromFile(ImageFileLoader.filename);
        System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);
        Texture2D mapTexture = new Texture2D(Screen.Game.GraphicsDevice, bitmap.Width, bitmap.Height,false,SurfaceFormat.Color);

        System.Drawing.Imaging.BitmapData data = 
            bitmap.LockBits(new System.Drawing.Rectangle(
            0, 0, bitmap.Width, bitmap.Height), 
            System.Drawing.Imaging.ImageLockMode.ReadOnly,System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        byte[] bytes = new byte[data.Height * data.Width*4];



        System.Runtime.InteropServices.Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);

        mapTexture.SetData<byte>(bytes, 0, data.Height * data.Width * 4);


        bitmap.UnlockBits(data);
        bitmap.Dispose();
        image.Dispose();

© Game Development or respective owner

Related posts about XNA

Related posts about c#