I have an in-memory Image
, I need to get a Stream
from it to write into an OpenXML document. Can someone please point me to the correct method.
views:
25answers:
1
+3
A:
You can use an overload of the Save
method that takes a Stream
as a parameter. To create a stream that exists in-memory, you can use MemoryStream
type. Something like this should work:
// Create new memory stream and save the image
var ms = new MemoryStream();
image.Save(ms, ImageFormat.Jpeg);
// Seek to the first byte in the stream, so that other classes who
// use it will start reading from the beginning
ms.Seek(0, SeekOrgin.Begin);
Now you can pass the newly created stream ms
to other objects (e.g. to save it in OpenXML
). See also:
- Image.Save method at MSDN
Tomas Petricek
2010-06-21 09:41:11