ImageDataSave Method (Stream) |
Namespace: Aspose.Words.Drawing
Is it the responsibility of the caller to dispose the stream object.
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); } } }