I am creating a level editor for my game that exports an image file, with each pixel representing a specific tile. I am creating this map as a Texture2D using the SetData function. I can display this texture on the screen, but when I try to save it using the SaveAsJpeg function, I just get an empty file. I can export all of my sprite sheets that were imported from the content folder without issue. Is there something that I need to do to that Texture2D before I can export it? (I am creating my game using the UWP option).
This is how I am generating the Texture2D.
`public void GenerateImage()
{
var colorData = new Color[30 * 17];
levelTex = new Texture2D(graphicsDevice, 30, 17);
for (int yPos = 0; yPos <= 29; yPos++)
{
for (int xPos = 0; xPos <= 16; xPos++)
{
colorData[(yPos * 17) + xPos] = new Color(100 + yPos, 200-xPos, 250);
}
}
levelTex.SetData(colorData,0, 30*17);``}`
This is how I am generating the file.
public void ExportLevel() { string pathName = Windows.Storage.KnownFolders.SavedPictures.Path;
try { System.IO.Directory.CreateDirectory(pathName + "/Hand Cannon Janky Reality Exported Levels"); System.IO.Stream myFile = System.IO.File.Create(pathName + "/Hand Cannon Janky Reality Exported Levels/" + "FileName.png"); levelTex.SaveAsJpeg(myFile, levelTex.Width, levelTex.Height); } catch (UnauthorizedAccessException exception) { System.Diagnostics.Debug.WriteLine("Cannot Save " + exception.Message); } }