ImageDataSave Method (Stream)

Saves the image into the specified stream.

Namespace:  Aspose.Words.Drawing
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public void Save(
	Stream stream
)

Parameters

stream
Type: System.IOStream
The stream where to save the image to.
Remarks

Is it the responsibility of the caller to dispose the stream object.

Examples
Shows how to save all the images from a document to the file system.
Document imgSourceDoc = new Document(MyDir + "Images.docx");

// Images are stored as shapes
// Get into the document's shape collection to verify that it contains 10 images
List<Shape> shapes = imgSourceDoc.GetChildNodes(NodeType.Shape, true).Cast<Shape>().ToList();
Assert.AreEqual(10, shapes.Count);

// We will use an ImageFormatConverter to determine an image's file extension
ImageFormatConverter formatConverter = new ImageFormatConverter();

// Go over all of the document's shapes
// If a shape contains image data, save the image in the local file system
for (int i = 0; i < shapes.Count; i++)
{
    ImageData imageData = shapes[i].ImageData;

    if (imageData.HasImage)
    {
        ImageFormat format = imageData.ToImage().RawFormat;
        string fileExtension = formatConverter.ConvertToString(format);

        using (FileStream fileStream = File.Create(ArtifactsDir + $"Drawing.SaveAllImages.{i}.{fileExtension}"))
        {
            imageData.Save(fileStream);
        }
    }
}
See Also