Back to Devexpress

DocumentImageCollection.Insert(DocumentPosition, DocumentImageSource) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentimagecollection-dot-insert-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentimagesource-x29.md

latest8.2 KB
Original Source

DocumentImageCollection.Insert(DocumentPosition, DocumentImageSource) Method

Inserts an image at the specified position in the document.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
DocumentImage Insert(
    DocumentPosition pos,
    DocumentImageSource imageSource
)
vb
Function Insert(
    pos As DocumentPosition,
    imageSource As DocumentImageSource
) As DocumentImage

Parameters

NameTypeDescription
posDocumentPosition

A DocumentPosition object specifying the position to insert an image.

| | imageSource | DocumentImageSource |

A DocumentImageSource object containing information about the image to insert.

|

Returns

TypeDescription
DocumentImage

A DocumentImage object specifying the inline image in the document.

|

Example

This sample code inserts an image into the document using the image source object created from the specified file.

View Example

csharp
Document document = server.Document;
DocumentPosition pos = document.Range.Start;
document.Images.Insert(pos, DocumentImageSource.FromFile("Documents\\beverages.png"));
vb
Dim document As Document = server.Document
Dim pos As DocumentPosition = document.Range.Start
document.Images.Insert(pos, DocumentImageSource.FromFile("Documents\beverages.png"))

The following code snippets (auto-collected from DevExpress Examples) contain references to the Insert(DocumentPosition, DocumentImageSource) 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-rich-text-editor-retain-original-image-uri-in-html-document/CS/Form1.cs#L19

csharp
DocumentPosition pos = richEditControl1.Document.CaretPosition;
richEditControl1.Document.Images.Insert(pos, DocumentImageSource.FromUri(imageUri, null));
embedImagesCheck.EditValue = true;

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

csharp
DocumentPosition pos = document.Range.Start;
document.Images.Insert(pos, DocumentImageSource.FromFile("beverages.png"));
#endregion #ImageFromFile

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

csharp
{
    document.Images.Insert(pos, DocumentImageSource.FromStream(s));
}

winforms-richedit-tables-simple-example/CS/TablesSimpleExample/Form1.cs#L113

csharp
// Insert the customer photo
document.Images.Insert(table[3, 1].Range.Start, DocumentImageSource.FromFile("photo.png"));

word-document-api-table-examples/CS/Program.cs#L93

csharp
//Insert the customer photo
document.Images.Insert(table[3, 0].Range.Start, DocumentImageSource.FromFile("photo.png"));

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

vb
Dim pos As DocumentPosition = doc.Paragraphs(doc.Paragraphs.Get(rangeFound.End).Index + 2).Range.Start
doc.Images.Insert(pos, DocumentImageSource.FromFile("Pictures\ReadersChoice.png"))
' Insert an image from a stream.

winforms-rich-text-editor-retain-original-image-uri-in-html-document/VB/Form1.vb#L15

vb
Dim pos As DocumentPosition = richEditControl1.Document.CaretPosition
richEditControl1.Document.Images.Insert(pos, DocumentImageSource.FromUri(imageUri, Nothing))
embedImagesCheck.EditValue = True

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

vb
Dim pos As DevExpress.XtraRichEdit.API.Native.DocumentPosition = document.Range.Start
            document.Images.Insert(pos, DevExpress.XtraRichEdit.API.Native.DocumentImageSource.FromFile("beverages.png"))
#End Region ' #ImageFromFile

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

vb
Using s As Stream = streamResInfo.Stream
    document.Images.Insert(pos, DocumentImageSource.FromStream(s))
End Using

winforms-richedit-tables-simple-example/VB/TablesSimpleExample/Form1.vb#L92

vb
' Insert the customer photo
document.Images.Insert(table(3, 1).Range.Start, DocumentImageSource.FromFile("photo.png"))
' Insert the customer info

See Also

InsertPicture

InsertPictureCommand

InsertFloatingObjectPictureCommand

DocumentImageSource

Shapes, Pictures, and Other Graphic Objects in Word Documents

DocumentImageCollection Interface

DocumentImageCollection Members

DevExpress.XtraRichEdit.API.Native Namespace