ImageData Class |
Namespace: Aspose.Words.Drawing
The ImageData type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | BiLevel |
Determines whether an image will be displayed in black and white.
|
![]() ![]() | Borders |
Gets the collection of borders of the image. Borders only have effect for inline images.
|
![]() ![]() | Brightness |
Gets or sets the brightness of the picture.
The value for this property must be a number from 0.0 (dimmest) to 1.0 (brightest).
|
![]() ![]() | ChromaKey |
Defines the color value of the image that will be treated as transparent.
|
![]() ![]() | Contrast |
Gets or sets the contrast for the specified picture. The value
for this property must be a number from 0.0 (the least contrast) to 1.0 (the greatest contrast).
|
![]() ![]() | CropBottom |
Defines the fraction of picture removal from the bottom side.
|
![]() ![]() | CropLeft |
Defines the fraction of picture removal from the left side.
|
![]() ![]() | CropRight |
Defines the fraction of picture removal from the right side.
|
![]() ![]() | CropTop |
Defines the fraction of picture removal from the top side.
|
![]() ![]() | GrayScale |
Determines whether a picture will display in grayscale mode.
|
![]() ![]() | HasImage |
Returns true if the shape has image bytes or links an image.
|
![]() ![]() | ImageBytes |
Gets or sets the raw bytes of the image stored in the shape.
|
![]() ![]() | ImageSize |
Gets the information about image size and resolution.
|
![]() ![]() | ImageType |
Gets the type of the image.
|
![]() ![]() | IsLink |
Returns true if the image is linked to the shape (when SourceFullName is specified).
|
![]() ![]() | IsLinkOnly |
Returns true if the image is linked and not stored in the document.
|
![]() ![]() | SourceFullName |
Gets or sets the path and name of the source file for the linked image.
|
![]() ![]() | Title |
Defines the title of an image.
|
Name | Description | |
---|---|---|
![]() | Equals | (Inherited from Object.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetType | (Inherited from Object.) |
![]() ![]() | Save(Stream) |
Saves the image into the specified stream.
|
![]() ![]() | Save(String) |
Saves the image into a file.
|
![]() ![]() | SetImage(Image) |
Sets the image that the shape displays.
|
![]() ![]() | SetImage(Stream) |
Sets the image that the shape displays.
|
![]() ![]() | SetImage(String) |
Sets the image that the shape displays.
|
![]() ![]() | ToByteArray |
Returns image bytes for any image regardless whether the image is stored or linked.
|
![]() ![]() | ToImage |
Gets the image stored in the shape as a Image object.
|
![]() ![]() | ToStream |
Creates and returns a stream that contains the image bytes.
|
![]() | ToString | (Inherited from Object.) |
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 ToByteArray, ToStream, ToImage or Save(String) 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(String) method. To link an image to a shape, set the SourceFullName property.
public void ExtractImagesToFiles() { Document doc = new Document(MyDir + "Images.docx"); NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true); 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++; } } }
DocumentBuilder builder = new DocumentBuilder(); string imageFileName = ImageDir + "Windows MetaFile.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(ArtifactsDir + "Image.CreateLinkedImage.doc");