officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-pictureformat-2cdb1ce8.md
Specifies the part of the picture to display in the document.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
RectangleOffset SourceRect { get; set; }
Property SourceRect As RectangleOffset
| 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%).
|
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%:
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);
Dim document As Document = wordProcessor.Document
' Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch
' Add a picture to the document.
Dim picture As Shape = 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.
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);
Dim document As Document = wordProcessor.Document
' Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch
' Add a picture to the document.
Dim picture As Shape = 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