Quantcast

Jump to content

» «
Photo

C# - XNA script question

3 replies to this topic
jackusCTB
  • jackusCTB

    Peon

  • Members
  • Joined: 29 Jun 2012
  • Belgium

#1

Posted 13 November 2013 - 01:48 PM

Hello guys, after some researches I found this snippet that convert a Texture2D file to an image file. How can I make an executable file from this? Thanks for the help!

public static System.Drawing.Image Texture2Image(Texture2D texture)
{
  if (texture == null)
  {
      return null;
  }
 
  if (texture.IsDisposed)
  {
      return null;
  }

  //Memory stream to store the bitmap data.
  MemoryStream ms = new MemoryStream();

  //Save the texture to the stream.
  texture.SaveAsPng(ms, texture.Width, texture.Height);

  //Seek the beginning of the stream.
  ms.Seek(0, SeekOrigin.Begin);

  //Create an image from a stream.
  System.Drawing.Image bmp2 = System.Drawing.Bitmap.FromStream(ms);

  //Close the stream, we nolonger need it.
  ms.Close();
  ms = null;
  return bmp2;
}

Bad.boy!
  • Bad.boy!

    SA modder

  • Feroci
  • Joined: 20 Jun 2010
  • Netherlands

#2

Posted 13 November 2013 - 03:33 PM

You have to load the texture from a file using ContentManager.Load, then setup a new FileStream and save the texture using the SaveAsPng function. It's pretty basic C#. I could write it for you if you still don't know how to do it.


jackusCTB
  • jackusCTB

    Peon

  • Members
  • Joined: 29 Jun 2012
  • Belgium

#3

Posted 13 November 2013 - 03:53 PM

You have to load the texture from a file using ContentManager.Load, then setup a new FileStream and save the texture using the SaveAsPng function. It's pretty basic C#. I could write it for you if you still don't know how to do it.

I appreciate the time and effort you have spent sorting out that problem, thanks for the kindness. First, I will try to do this by myself, then if I need some help I may ask help to you.


trip
  • trip

    ~

  • Andolini Mafia Family
  • Joined: 10 Oct 2007
  • United-States
  • Contribution Award [GTAF]
    Contribution Award [Gen Chat]

#4

Posted 13 November 2013 - 11:49 PM Edited by trip, 13 November 2013 - 11:50 PM.

Do you have visual studio and the xna libraries installed?
http://xbox.create.m...getting_started
Everything you'd need is free.

You can then paste that function/sub into your game.cs file and toss whatever texture2d to it you want.



Just curious; what is your mission? I've been using xna since the first beta and love it.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users