Export Graphics as png on game save and import them on game load?

Does monogame support the following?
-Exporting graphics as png on game save
-Importing graphics as png on game load

preferably in specific sub folders?

I want to make something similar to SMBX which is a super mario editor which stores data like this…

\ root folder
 | world folder
 \ graphics folder
  | npcs folder containing png files for npcs
  | blocks folder containing png files for blocks
  | backgrounds folder containing png files for backgrounds
 \ sound folder
  | npcs folder containing ogg files for npcs
  | blocks folder containing ogg files for blocks
  | backgrounds folder containing ogg files for backgrounds
 \ script folder
  | npcs folder containing lua files for npcs
  | blocks folder containing lua files for blocks
  | backgrounds folder containing lua files for backgrounds

or maybe something like this…

\ root folder
 | npc folder containing folders for each npc
 | blocks folder containing folders for each block
 | background folder  containing folders for each background

this is just a question wondering if monogame can do this?

You can use the Texture2D.SaveAsPng method to save a texture to a stream. Just open a FileStream where you want to write it. To load them back in you can use Texture2D.FromStream on a FileStream.

1 Like

Like this (suffixed if needed) from my code to save screenshots/RTs:

string filenamesuffix = DateTime.Now.ToString("yyyy-MM-dd HHmmss.ffffff");
if(_DGC_AnamorphicBloom._RT_Luminance != null)
{
	using(Stream sw = File.OpenWrite("_DGC_AnamorphicBloom-_RT_Luminance" + filenamesuffix + ".png"))
	{
		_DGC_AnamorphicBloom._RT_Luminance.SaveAsPng(sw, _DGC_AnamorphicBloom._RT_Luminance.Width, _DGC_AnamorphicBloom._RT_Luminance.Height);
	}
}