I’m getting Image (actually instance of Bitmap class) from resources, and (to write it to rtf stream) – I need it’s raw data back.
Also, Image.Save method can’t be used, because it seems to close stream it saving to, and I need to append to RTF file. I do not want to create new stream, save image to it, then copy it to RTF stream because of performance issues.
Create a filter stream that passes through to the stream you want to append to, but doesn’t close that stream when it is itself closed:
Then you’ve no longer got the issue of the stream being closed, as it doesn’t matter.
The bits to deal with seeking to new positions is because some image formats are written in a non-sequential manner. It won’t work if the underlying stream doesn’t support it, but then that wouldn’t work anyway.