Edit this page

Cropping

CropTool is one of the tool that come out-of-the-box with RadImageEditor and gives the opportunity to crop a given area from an image. The tool provides some customization options that are explained in detail in this topic.

When the tool is invoked a rectangle is shown over the image. It is called crop adorner and visualizes the part of the images that is going to be cropped when the tool is invoked.

Crop AdornerRad Image Editor How To Use Crop 01

The tool is located in the Telerik.Windows.Media.Imaging.Tools namespace and can be defined in XAML as demonstrated in Example 1.

Example 1: Create CropTool

<tools:CropTool />

InitialSize

The InitialSize property is of type Size and determines the initial size of the crop adorner. Unless explicitly set, the rectangle has width and height equal to 80% of the width and height of the image that is shown in the control.

Example 2 demonstrates how to set the initial size of the tool in XAML and in code.

Example 2: Set initial size

<tools:CropTool InitialSize="150,150" />

Example 2: Set initial size

CropTool cropTool = new CropTool();
cropTool.InitialSize = new Size(150, 150);
Dim cropTool As New CropTool()
cropTool.InitialSize = New Size(150, 150)

FixedSize

The FixedSize property is of type Size and specifies the only size that is allowed for the Crop tool. This means that the crop adorner is shown with those dimensions and resizing it is not possible.

Example 3 shows how to set fixed size in XAML and in code.

Example 3: Set fixed size

<tools:CropTool FixedSize="200,100" />

Example 3: Set fixed size

CropTool cropTool = new CropTool();
cropTool.FixedSize = new Size(200, 100);
Dim cropTool As New CropTool()
cropTool.FixedSize = New Size(200, 100)

If the image shown in RadImageEditor has smaller dimensions than the ones set for the tool's initial or fixed size, the crop adorner gets limited to the boundaries of the image. For example, if the image's size is (200,300) and you set fixed size to the crop tool (300,50), the crop rectangle will be shown with size (200,50).

AspectRatio

The AspectRatio property of the crop tool determines whether the width and height of the crop adorner are in linear dependence. The value can be a positive decimal number and specifying it "locks" the ratio between the width and height of the crop rectangle.

The calculated ratio value corresponds to the width of the adorner divided by its height. This means that if you want a crop rectangle that has a width 2 times smaller than its height, you should set value 0.5 to the AspectRatio. Example 3 shows how this can be done in XAML and in code behind.

Example 3: Set fixed aspect ratio

<tools:CropTool AspectRatio="0.5"/>

Example 3: Set fixed aspect ratio

CropTool cropTool = new CropTool();
cropTool.AspectRatio = 0.5;
Dim cropTool As New CropTool()
cropTool.AspectRatio = 0.5

You can crop an image with fixed ration between the width and height without setting the FixedRatio property. Just press and hold the Shift key while dragging the crop adorner.

See Also