Defines an image for a shape.
For a list of all members of this type, see ImageData Members.
System.Object
Aspose.Words.Drawing.ImageData
[Visual Basic]
Public Class ImageData
[C#]public class ImageData
Remarks
Use the ImageData property to access and modify the image inside a shape. You do not create instances of the ImageData class directly.
An image can be stored inside a shape, linked to external file or both (linked and stored in the document).
Regardless of whether the image is stored inside the shape or linked, you can always access the actual image using the ToImage, ToStream and Save methods. If the image is stored inside the shape, you can also directly access it using the ImageBytes property.
To store an image inside a shape use the SetImage method. To link an image to a shape, set the SourceFullName property.
Example
Shows how to extract images from a document and save them as files.
[C#]
[Test]
public void ExtractImagesToFiles()
{
Document doc = new Document(MyDir + "Image.SampleImages.doc");
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true, false);
int imageIndex = 0;
foreach (Shape shape in shapes)
{
if (shape.HasImage)
{
string imageFileName = string.Format("Image.ExportImages.{0} Out.{1}", imageIndex, shape.ImageData.ImageType);
shape.ImageData.Save(MyDir + imageFileName);
imageIndex++;
}
}
}[Visual Basic]
<Test> _
Public Sub ExtractImagesToFiles()
Dim doc As Document = New Document(MyDir & "Image.SampleImages.doc")
Dim shapes As NodeCollection = doc.GetChildNodes(NodeType.Shape, True, False)
Dim imageIndex As Integer = 0
For Each shape As Shape In shapes
If shape.HasImage Then
Dim imageFileName As String = String.Format("Image.ExportImages.{0} Out.{1}", imageIndex, shape.ImageData.ImageType)
shape.ImageData.Save(MyDir & imageFileName)
imageIndex += 1
End If
Next shape
End SubShows how to insert a linked image into a document.
[C#]
DocumentBuilder builder = new DocumentBuilder();
string imageFileName = MyDir + "Hammer.wmf";
builder.Write("Image linked, not stored in the document: ");
Shape linkedOnly = new Shape(builder.Document, ShapeType.Image);
linkedOnly.WrapType = WrapType.Inline;
linkedOnly.ImageData.SourceFullName = imageFileName;
builder.InsertNode(linkedOnly);
builder.Writeln();
builder.Write("Image linked and stored in the document: ");
Shape linkedAndStored = new Shape(builder.Document, ShapeType.Image);
linkedAndStored.WrapType = WrapType.Inline;
linkedAndStored.ImageData.SourceFullName = imageFileName;
linkedAndStored.ImageData.SetImage(imageFileName);
builder.InsertNode(linkedAndStored);
builder.Writeln();
builder.Write("Image stored in the document, but not linked: ");
Shape stored = new Shape(builder.Document, ShapeType.Image);
stored.WrapType = WrapType.Inline;
stored.ImageData.SetImage(imageFileName);
builder.InsertNode(stored);
builder.Writeln();
builder.Document.Save(MyDir + "Image.CreateLinkedImage Out.doc");[Visual Basic]
Dim builder As DocumentBuilder = New DocumentBuilder()
Dim imageFileName As String = MyDir & "Hammer.wmf"
builder.Write("Image linked, not stored in the document: ")
Dim linkedOnly As Shape = New Shape(builder.Document, ShapeType.Image)
linkedOnly.WrapType = WrapType.Inline
linkedOnly.ImageData.SourceFullName = imageFileName
builder.InsertNode(linkedOnly)
builder.Writeln()
builder.Write("Image linked and stored in the document: ")
Dim linkedAndStored As Shape = New Shape(builder.Document, ShapeType.Image)
linkedAndStored.WrapType = WrapType.Inline
linkedAndStored.ImageData.SourceFullName = imageFileName
linkedAndStored.ImageData.SetImage(imageFileName)
builder.InsertNode(linkedAndStored)
builder.Writeln()
builder.Write("Image stored in the document, but not linked: ")
Dim stored As Shape = New Shape(builder.Document, ShapeType.Image)
stored.WrapType = WrapType.Inline
stored.ImageData.SetImage(imageFileName)
builder.InsertNode(stored)
builder.Writeln()
builder.Document.Save(MyDir & "Image.CreateLinkedImage Out.doc")Requirements
Namespace: Aspose.Words.Drawing
Assembly: Aspose.Words (in Aspose.Words.dll)
See Also
ImageData Members | Aspose.Words.Drawing Namespace