Normally, this error occurs because the output stream is in use when you try to save, but since you are outputting to a MemoryStream that is not the case.
Sorry, but the problem is not in teh code you show - it's a lot further back...
The problem is probably that the stream you used to create the image in the first place is no longer available - it has been closed or disposed by the time you get to the Save method. And that doesn't work!
Try this:
When you load the image in the first place, create a new image as a copy of the actual picture, and use that - you can dispose of the original version you read in. For example:
Image myImage;
using (Image inputImage = Image.FromFile(@"D:\Temp\MyPic.jpg"))
{
myImage = new Bitmap(inputImage);
}
Because the new image is not associated with a file or stream, it can be saved with no problem.