Back to Devexpress

PictureFormat.SourceRect Property

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-pictureformat-2cdb1ce8.md

latest4.1 KB
Original Source

PictureFormat.SourceRect Property

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

Declaration

csharp
RectangleOffset SourceRect { get; set; }
vb
Property SourceRect As RectangleOffset

Property Value

TypeDescription
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%:

csharp
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);
vb
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.

csharp
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);
vb
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

PictureFormat Interface

PictureFormat Members

DevExpress.XtraRichEdit.API.Native Namespace