Alex Rivera | Logout

Saving a bitmap into a MemoryStream

Asked 2011-12-29T10:00:00.033
41

Should I allocate the memory or just the object of the memory stream: Is this OK?

MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);

If I need to define the MemoryStream size, how can I get it from Bitmap?

Edit
Report

1 Answer

7

You don't need to preallocate memory.

You can get the size afterwards with memoryStream.Length.


After you've done what you need to with your memoryStream, be sure to dispose it (or wrap it all in a using statement).

answered 2011-12-29T10:01:50.467

Your Answer