XNA.Texture2D to System.Drawing.Bitmap I am sure this answered my question but it linked an external site and is no longer available.
I am using a windows form in an
You can use two methods that allow you to create a Bitmap, use Texture2D.SaveAsJpeg()
or Texture2D.SaveAsPng()
.
MemoryStream memoryStream = new MemoryStream();
Texture2D texture = Content.Load<Texture2D>( "Images\\test" );
texture.SaveAsJpeg( memoryStream, texture.Width, texture.Height ); //Or SaveAsPng( memoryStream, texture.Width, texture.Height )
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( memoryStream );
This works for me. If there are problems with it please let me know.
public static Image Texture2Image(Texture2D texture)
{
Image img;
using (MemoryStream MS = new MemoryStream())
{
texture.SaveAsPng(MS, texture.Width, texture.Height);
//Go To the beginning of the stream.
MS.Seek(0, SeekOrigin.Begin);
//Create the image based on the stream.
img = Bitmap.FromStream(MS);
}
return img;
}