I want to use a Texture2d as a system.drawing.bitmap

后端 未结 2 1891
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 01:29

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

2条回答
  •  旧时难觅i
    2020-12-20 01:56

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

提交回复
热议问题