officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shapecollection-dot-insertpicture-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-system-dot-drawing-dot-image-x29.md
Inserts a picture in the document.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
[Browsable(false)]
Shape InsertPicture(
DocumentPosition pos,
Image image
)
<Browsable(False)>
Function InsertPicture(
pos As DocumentPosition,
image As Image
) As Shape
| Name | Type | Description |
|---|---|---|
| pos | DocumentPosition |
The position of the picture’s anchor.
| | image | Image |
The image to insert.
|
| Type | Description |
|---|---|
| Shape |
The picture embedded in the document.
|
The InsertPicture method positions a floating picture at the top-left corner of the page that contains the picture’s anchor. The TextWrapping property is set to InFrontOfText.
The Word Processing Document API and Rich Text Editors support the following image types:
The example below inserts a picture and specifies its horizontal alignment.
Document document = wordProcessor.Document;
document.AppendText("Line One\nLine Two\nLine Three");
Shape myPicture = document.Shapes.InsertPicture(document.CreatePosition(15),
System.Drawing.Image.FromFile("Documents\\beverages.png"));
myPicture.HorizontalAlignment = ShapeHorizontalAlignment.Center;
Dim document As Document = wordProcessor.Document
document.AppendText("Line One" & vbLf & "Line Two" & vbLf & "Line Three")
Dim myPicture As Shape = document.Shapes.InsertPicture(document.CreatePosition(15), System.Drawing.Image.FromFile("Documents\beverages.png"))
myPicture.HorizontalAlignment = ShapeHorizontalAlignment.Center
The following code snippets (auto-collected from DevExpress Examples) contain references to the InsertPicture(DocumentPosition, Image) 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/Shapes.cs#L16
document.AppendText("Line One\nLine Two\nLine Three");
Shape myPicture = document.Shapes.InsertPicture(document.CreatePosition(15),
System.Drawing.Image.FromFile("beverages.png"));
word-document-api-examples/CS/CodeExamples/ShapesActions.cs#L30
// Insert a picture at the specified position from the file.
Shape myPicture = document.Shapes.InsertPicture(document.CreatePosition(15),
System.Drawing.Image.FromFile("Documents\\beverages.png"));
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Shapes.vb#L15
document.AppendText("Line One" & Global.Microsoft.VisualBasic.Constants.vbLf & "Line Two" & Global.Microsoft.VisualBasic.Constants.vbLf & "Line Three")
Dim myPicture As DevExpress.XtraRichEdit.API.Native.Shape = document.Shapes.InsertPicture(document.CreatePosition(15), System.Drawing.Image.FromFile("beverages.png"))
myPicture.HorizontalAlignment = DevExpress.XtraRichEdit.API.Native.ShapeHorizontalAlignment.Center
word-document-api-examples/VB/CodeExamples/ShapesActions.vb#L32
' Insert a picture at the specified position from the file.
Dim myPicture As DevExpress.XtraRichEdit.API.Native.Shape = document.Shapes.InsertPicture(document.CreatePosition(15), System.Drawing.Image.FromFile("Documents\beverages.png"))
' Specify the picture alignment.
See Also