Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a tile based game, and I'm working for support of tilesets. I'm trying to make it so that a Texture2D is set as a chosen PNG file. I can do this with no problem f I load the image into the content pipeline, but the level editor will be used by people without access to the content pipeline. How do I go about doing this?

share|improve this question

A bit late for Raj but for anyone else...

        string PictureLocation = @"D:\PictureName.png";
        Texture2D Newtexture =  LoadPicture(PictureLocation);

        string PictureDestination = @"D:\NewPictureName.png";
        SavePicture(PictureDestination, Newtexture);

    public static Texture2D LoadPicture(string Filename)
    {
        FileStream setStream = File.Open(Filename, FileMode.Open);
        StreamReader reader = new StreamReader(setStream);
        Texture2D NewTexture = Texture2D.FromStream(graphicsDevice, setStream);
        setStream.Dispose();
        return NewTexture;
    }

    public static void SavePicture(string Filename, Texture2D TextureToSave)
    {
        FileStream setStream = File.Open(Filename, FileMode.Create);
        StreamWriter writer = new StreamWriter(setStream);
        TextureToSave.SaveAsPng(setStream, TextureToSave.Width, TextureToSave.Height);
        setStream.Dispose();
    }

Reading in and saving in a new location for PNG and JPEG (I think they are the only supported, but that should be good enough :).

Hope this helps anybody else with a similar problem. Stoort.

share|improve this answer

You can call the Texture2D.FromStream static method. Just pass it a stream to the png file. I'm pretty sure it works without the content pipeline.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.