Skip to main content

PictureFormat.SourceRect Property

Specifies the part of the picture to display in the document.

Namespace: DevExpress.XtraRichEdit.API.Native

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

NuGet Package: DevExpress.RichEdit.Core

Declaration

RectangleOffset SourceRect { get; set; }

Property Value

Type Description
RectangleOffset

An object that specifies offsets (in percentage) from the edges of a shape’s bounding box to the center. Valid values range from -1000 (-100 000%) to 1000 (100 000%).

Remarks

Use positive values for the SourceRect property to crop a picture. The picture is stretched to keep its size. The example below crops the bottom of the picture by 30%:

Rich_PictureFormat_SourceRect_Positive

Document document = wordProcessor.Document;
// Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Add a picture to the document.
Shape picture = document.Shapes.InsertPicture(document.Range.Start, DocumentImageSource.FromFile("Picture_Dog.png"));
// Set the picture's width and height.
picture.Width = 2.5f;
picture.Height = 1.8f;
// Crop the bottom of the picture by 30%.
picture.PictureFormat.SourceRect = new RectangleOffset(0f, 0f, 0f, 0.3f);

If the SourceRect property values are negative, empty spaces appear at the picture’s edges. The example below displays blank bands of equal width (10% of the picture width) on the left and right sides of the picture.

Rich_PictureFormat_SourceRect_Negative

Document document = wordProcessor.Document;
// Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Add a picture to the document.
Shape picture = document.Shapes.InsertPicture(document.Range.Start, DocumentImageSource.FromFile("Picture_Dog.png"));
// Set the picture's width and height.
picture.Width = 2.5f;
picture.Height = 1.8f;
// Reduce the picture size to add empty spaces to its left and right edges.
picture.PictureFormat.SourceRect = new RectangleOffset(-0.1f, 0f, -0.1f, 0f);
See Also