Back to Devexpress

SubDocument.Images Property

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-subdocument-31804a12.md

latest7.1 KB
Original Source

SubDocument.Images Property

Provides access to the collection of all images (inline and floating pictures) in the document .

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
DocumentImageCollection Images { get; }
vb
ReadOnly Property Images As DocumentImageCollection

Property Value

TypeDescription
DocumentImageCollection

A DocumentImageCollection object that is a collection of images in the current document.

|

Remarks

To get a collection of images located in the specified range, call the Get method of the DocumentImageCollection object. Use a ReadOnlyDocumentImageCollection collection returned by this method to count images in the document or access individual images.

To access document shapes, use the SubDocument.Shapes property.

Example

The code sample below retrieves all images in the specific document range and exports them in the PNG format.

View Example

csharp
Document document = server.Document;
document.LoadDocument("Documents\\MovieRentals.docx", DocumentFormat.Docx);
DocumentRange myRange = document.CreateRange(0, 100);

// Obtain all images im the specific range:
ReadOnlyDocumentImageCollection images = document.Images.Get(myRange);

// Export the retrieved images as png files:
if (images.Count > 0)
{
    DevExpress.Office.Utils.OfficeImage myImage = images[0].Image;
    System.Drawing.Image image = myImage.NativeImage;
    string imageName = String.Format("Image_at_pos_{0}.png", images[0].Range.Start.ToInt());
    image.Save(imageName);
    System.Diagnostics.Process.Start("explorer.exe", "/select," + imageName);
}
vb
Dim document As Document = server.Document
document.LoadDocument("Documents\MovieRentals.docx", DocumentFormat.Docx)
Dim myRange As DocumentRange = document.CreateRange(0, 100)

' Obtain all images im the specific range:
Dim images As ReadOnlyDocumentImageCollection = document.Images.Get(myRange)

' Export the retrieved images as png files:
If images.Count > 0 Then
    Dim myImage As DevExpress.Office.Utils.OfficeImage = images(0).Image
    Dim image As System.Drawing.Image = myImage.NativeImage
    Dim imageName As String = String.Format("Image_at_pos_{0}.png", images(0).Range.Start.ToInt())
    image.Save(imageName)
    System.Diagnostics.Process.Start("explorer.exe", "/select," & imageName)
End If

The following code snippets (auto-collected from DevExpress Examples) contain references to the Images property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/InlinePictures.cs#L24

csharp
document.LoadDocument("Documents//Grimm.docx");
ReadOnlyDocumentImageCollection images = document.Images;
// If the width of an image exceeds 50 millimeters,

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/InlinePicturesActions.cs#L34

csharp
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
ReadOnlyDocumentImageCollection images = document.Images;
// If the width of an image exceeds 50 millimeters,

word-document-api-examples/CS/CodeExamples/InlinePictureActions.cs#L26

csharp
// Obtain all images contained in the document.
ReadOnlyDocumentImageCollection images = document.Images;

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/InlinePictures.vb#L22

vb
document.LoadDocument("Documents//Grimm.docx")
Dim images As DevExpress.XtraRichEdit.API.Native.ReadOnlyDocumentImageCollection = document.Images
' If the width of an image exceeds 50 millimeters,

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/InlinePicturesActions.vb#L28

vb
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
Dim images As ReadOnlyDocumentImageCollection = document.Images
' If the width of an image exceeds 50 millimeters,

word-document-api-examples/VB/CodeExamples/InlinePictureActions.vb#L24

vb
' Obtain all images contained in the document.
Dim images As DevExpress.XtraRichEdit.API.Native.ReadOnlyDocumentImageCollection = document.Images
' If the image width exceeds 50 millimeters,

See Also

Shapes, Pictures, and Other Graphic Objects in Word Documents

DocumentImage

DocumentImageSource

SubDocument Interface

SubDocument Members

DevExpress.XtraRichEdit.API.Native Namespace