No prob, glad I could help
The ToStream method is likely slow for two reasons:
- When you write primitive data types to a stream, each write invokes other functionality than a simple memory write. This is as opposed to using your own array, which is essentially just a linear block of memory with fast access. The latter is more unsafe, but very much faster approach. And it is not actually unsafe if you know what you're doing (do sanity checking on memory boundaries at high level etc.)
- The image codec itself is slow to instantiate/invoke. Apart from switching to a faster image i/o library, there's little you can do about the issue itself. However, you could use a separate thread if you need to save and image while keeping rendering alive - just map/copy the raw pixels in the main drawing thread, and do the actual file i/o in the secondary thread.