public void Write(Stream stream, ICanvas canvas) { var idReset = new IdReset(); idReset.Reset(canvas); var idPreprocessor = new IdPreprocessor(); var bpoints = idPreprocessor.Process(canvas); var canvasWriter = new CanvasWriter(); using (var writer = new BinaryWriter(stream)) { canvasWriter.Write(writer, ref bpoints, canvas); idReset.Reset(canvas); } }