ToByteArray
Contents
[
Hide
]ImageData.ToByteArray method
Returns image bytes for any image regardless whether the image is stored or linked.
public byte[] ToByteArray()
Remarks
If the image is linked, downloads the image every time it is called.
Examples
Shows how to create an image file from a shape’s raw image data.
Document imgSourceDoc = new Document(MyDir + "Images.docx");
Shape imgShape = (Shape) imgSourceDoc.GetChild(NodeType.Shape, 0, true);
Assert.True(imgShape.HasImage);
// ToByteArray() returns the array stored in the ImageBytes property.
Assert.AreEqual(imgShape.ImageData.ImageBytes, imgShape.ImageData.ToByteArray());
// Save the shape's image data to an image file in the local file system.
using (Stream imgStream = imgShape.ImageData.ToStream())
{
using (FileStream outStream = new FileStream(ArtifactsDir + "Drawing.GetDataFromImage.png",
FileMode.Create, FileAccess.ReadWrite))
{
imgStream.CopyTo(outStream);
}
}
See Also
- class ImageData
- namespace Aspose.Words.Drawing
- assembly Aspose.Words