ImageDataImageBytes Property

Gets or sets the raw bytes of the image stored in the shape.

Namespace:  Aspose.Words.Drawing
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public byte[] ImageBytes { get; set; }

Property Value

Type: Byte
Remarks

Setting the value to null or an empty array will remove the image from the shape.

Returns null if the image is not stored in the document (e.g the image is probably linked in this case).

Examples
Shows how to access raw image data in a shape's ImageData 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);
    }
}
See Also