Copy MemoryStream to FileStream and save the file?

You need to reset the position of the stream before copying.

outStream.Position = 0;
outStream.CopyTo(fileStream);

You used the outStream when saving the file using the imageFactory. That function populated the outStream. While populating the outStream the position is set to the end of the populated area. That is so that when you keep on writing bytes to the steam, it doesn’t override existing bytes. But then to read it (for copy purposes) you need to set the position to the start so you can start reading at the start.

Leave a Comment