public static bool SaveToFile(string filePath, Texture texture) { TextureStorage storage = new TextureStorage(filePath, texture); using (FileStream outputStream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { using (BinaryWriter outputWriter = new BinaryWriter(outputStream, storage.Encoding)) { if (!storage.Write(outputWriter)) { Debug.Assert(false, "Cannot write a texture file!"); return(false); } } } return(true); }
public static Texture LoadFromFile(string filePath) { TextureStorage storage = new TextureStorage(filePath); using (FileStream inputStream = new FileStream(storage.LibraryPath, FileMode.Open, FileAccess.Read)) { using (BinaryReader inputReader = new BinaryReader(inputStream, storage.Encoding)) { if (!storage.Parse(inputReader)) { return(null); } } } string name = Path.GetFileNameWithoutExtension(filePath); return(new Texture(name, storage.Pixels, storage.Width, storage.Height)); }