ShapeImageData Property

Provides access to the image of the shape. Returns null if the shape cannot have an image.

Namespace:  Aspose.Words.Drawing
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.5
Syntax
public ImageData ImageData { get; }

Property Value

Type: ImageData
Examples
Shows how to extract images from a document and save them as files.
Document doc = new Document(MyDir + "Images.docx");

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
Assert.AreEqual(9, shapes.Count(s => ((Shape)s).HasImage));

int imageIndex = 0;
foreach (Shape shape in shapes.OfType<Shape>())
{
    if (shape.HasImage)
    {
        string imageFileName =
            $"File.ExtractImagesToFiles.{imageIndex}{FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType)}";
        shape.ImageData.Save(ArtifactsDir + imageFileName);
        imageIndex++;
    }
}
Examples
Shows how to insert a linked image into a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

string imageFileName = ImageDir + "Windows MetaFile.wmf";

builder.Write("Image linked, not stored in the document: ");

Shape shape = new Shape(builder.Document, ShapeType.Image);
shape.WrapType = WrapType.Inline;
shape.ImageData.SourceFullName = imageFileName;

builder.InsertNode(shape);
builder.Writeln();

builder.Write("Image linked and stored in the document: ");

shape = new Shape(builder.Document, ShapeType.Image);
shape.WrapType = WrapType.Inline;
shape.ImageData.SourceFullName = imageFileName;
shape.ImageData.SetImage(imageFileName);

builder.InsertNode(shape);
builder.Writeln();

builder.Write("Image stored in the document, but not linked: ");

shape = new Shape(builder.Document, ShapeType.Image);
shape.WrapType = WrapType.Inline;
shape.ImageData.SetImage(imageFileName);

builder.InsertNode(shape);
builder.Writeln();

doc.Save(ArtifactsDir + "Image.CreateLinkedImage.docx");
See Also