Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Use Word Processing Document API To Replace a Picture with Another Picture

The following example demonstrates how to use the PictureFormat.SetPicture method to replace a picture with another picture and maintain the original format, size, and position:

Rich_PictureFormat_SetPicture

Document document = wordProcessor.Document;

// Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;

// Insert a picture.
Shape picture = document.Shapes.InsertPicture(document.Range.Start, System.Drawing.Image.FromFile("Picture_Dog.png"));

// Set the picture size.
picture.Size = new SizeF(3f, 2.5f);

// Align the picture.
picture.HorizontalAlignment = ShapeHorizontalAlignment.Center;
picture.VerticalAlignment = ShapeVerticalAlignment.Top;

// Change the picture's form.
picture.PictureFormat.Preset = ShapeGeometryPreset.RoundedRectangle;

// Display a border around the picture.
picture.Line.Color = Color.Black;

// Replace the picture.
picture.PictureFormat.SetPicture(System.Drawing.Image.FromFile("Picture_Cat.png"));