ImageDataToStream Method |
Namespace: Aspose.Words.Drawing
If the image bytes are stored in the shape, creates and returns a MemoryStream object.
If the image is linked and stored in a file, opens the file and returns a FileStream object.
If the image is linked and stored in an external URL, downloads the file and returns a MemoryStream object.
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); // ToByteArray() returns the value of the ImageBytes property Assert.AreEqual(shapes[0].ImageData.ImageBytes, shapes[0].ImageData.ToByteArray()); // Put the shape's image data into a stream // Then, put the image data from that stream into another stream which creates an image file in the local file system using (Stream imgStream = shapes[0].ImageData.ToStream()) { using (FileStream outStream = new FileStream(ArtifactsDir + "Drawing.GetDataFromImage.png", FileMode.Create)) { imgStream.CopyTo(outStream); } }