Back to Devexpress

ReadOnlyDocumentImageCollection.Get(DocumentRange) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-readonlydocumentimagecollection-dot-get-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentrange-x29.md

latest9.1 KB
Original Source

ReadOnlyDocumentImageCollection.Get(DocumentRange) Method

Gets all images (inline and floating pictures) located in the specified document range.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
ReadOnlyDocumentImageCollection Get(
    DocumentRange range
)
vb
Function Get(
    range As DocumentRange
) As ReadOnlyDocumentImageCollection

Parameters

NameTypeDescription
rangeDocumentRange

A DocumentRange specifying the range in which to search for images.

|

Returns

TypeDescription
ReadOnlyDocumentImageCollection

A ReadOnlyDocumentImageCollection object specifying the read-only collection of images.

|

Remarks

The method can be accessed by the RichEditControl.Document.Images.Get or RichEditDocumentServer.Document.Images.Get notation.

Note

If you operate with a selection range, the Get method should be enclosed within a DocumentRange.BeginUpdateDocument - DocumentRange.EndUpdateDocument method pair. Otherwise, an incorrect document model might be selected, resulting in an exception “Error: specified document position or range belongs to other document or subdocument” being thrown.

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 Get(DocumentRange) method.

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/Export.cs#L17

csharp
DocumentRange docRange = document.Paragraphs[2].Range;
ReadOnlyDocumentImageCollection docImageColl = document.Images.Get(docRange);
if (docImageColl.Count > 0)

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/ExportActions.cs#L18

csharp
DocumentRange docRange = document.Paragraphs[2].Range;
ReadOnlyDocumentImageCollection docImageColl = document.Images.Get(docRange);
if (docImageColl.Count > 0)

winforms-richedit-layout-api-practical-usage/CS/WindowsFormsApplication1/DocumentLayoutHelper/RichEditDocumentLayoutAnalyzer.cs#L15

csharp
ReadOnlyShapeCollection shapes = subDocument.Shapes.Get(subDocument.CreateRange(docPosition, 1));
ReadOnlyDocumentImageCollection images = subDocument.Images.Get(subDocument.CreateRange(docPosition, 1));

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

csharp
// Obtain all images in the target range.
ReadOnlyDocumentImageCollection images = document.Images.Get(myRange);

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Export.vb#L15

vb
Dim docRange As DevExpress.XtraRichEdit.API.Native.DocumentRange = document.Paragraphs(CInt((2))).Range
Dim docImageColl As DevExpress.XtraRichEdit.API.Native.ReadOnlyDocumentImageCollection = document.Images.[Get](docRange)
If docImageColl.Count > 0 Then

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/ExportActions.vb#L15

vb
Dim docRange As DocumentRange = document.Paragraphs(2).Range
Dim docImageColl As ReadOnlyDocumentImageCollection = document.Images.Get(docRange)
If docImageColl.Count > 0 Then

word-document-api-insert-inline-pictures/VB/InlinePictures/Program.vb#L50

vb
' Scale down images in the document body.
Dim images As ReadOnlyDocumentImageCollection = server.Document.Images.Get(doc.Range)
For i As Integer = 0 To images.Count - 1

winforms-richedit-layout-api-practical-usage/VB/WindowsFormsApplication1/DocumentLayoutHelper/RichEditDocumentLayoutAnalyzer.vb#L18

vb
Dim shapes As ReadOnlyShapeCollection = subDocument.Shapes.Get(subDocument.CreateRange(docPosition, 1))
Dim images As ReadOnlyDocumentImageCollection = subDocument.Images.Get(subDocument.CreateRange(docPosition, 1))

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

vb
' Obtain all images in the target range.
Dim images As DevExpress.XtraRichEdit.API.Native.ReadOnlyDocumentImageCollection = document.Images.[Get](myRange)
If images.Count > 0 Then

See Also

Images

ReadOnlyDocumentImageCollection Interface

ReadOnlyDocumentImageCollection Members

DevExpress.XtraRichEdit.API.Native Namespace