XNA.Texture2D to System.Drawing.Bitmap
Asked Answered
P

2

0

I need load XNA.Texture2D to PictureBox.

i've tried this: http://www.gamedev.net/community/forums/viewreply.asp?ID=3224621 but it doesn't work. Any suggestions?

Paranoid answered 4/5, 2010 at 20:41 Comment(0)
A
2

You should be able to use that method, but make sure that your XNA Texture2D is created with a format of 32bbpARGB. Any other format will prevent that method from working directly.

Anaptyxis answered 4/5, 2010 at 20:45 Comment(2)
[Texture2D = bgr32]. but there is another problem, how could i 'reformat' texture to 32bbpARGB?Paranoid
for (int i = 0; i < 4 * texture.Width * texture.Height; i += 4) { byte tmp = textureData[i + 0]; textureData[i + 0] = textureData[i + 2]; //b textureData[i + 2] = tmp; //r textureData[i + 3] = 255; //A } it doesen't take too much time, but could be improved.Paranoid
U
2

Easier way to do it is save the Texture2D using Texture2D.SaveAsPng or Texture2D.SaveAsJpeg to a memory stream and the open the virtual file using Bitmap(Stream).

Unreserve answered 13/2, 2012 at 23:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.