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?
2 Answers
\$\begingroup\$ \$\endgroup\$
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.
\$\begingroup\$ \$\endgroup\$
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); 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.