New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Cropping Images

  • Undo
  • Redo
  • Crop
Zoom:100%Size:0x0pxPos.:(-,-)Last Action:None

RadImageEditor provides a tool that enables the user to remove outer parts of an image to improve framing on the image (bring the focus to the subject), give an accent to a subject from the image or change the aspect ratio. This example demonstrates how to enable and use the Crop tool. Basically, an ImageEditorTool, with CommandName="Crop", needs to be created for the Crop tool to be rendered on the control's ToolBar.

How the Crop dialog works:

  • The dimensions of the crop rectangle (and the resulting image) are always retrieved from the Width and Height text-boxes, and the image is actually cropped when the Crop button is clicked.
  • The Aspect Ratio DropDownList contains a list of preset sizes for the crop box. Upon selection, the values in the Width and Height inputs are changed. And the movable crop box automatically reflects the selection.
  • The X and Y text-boxes specify the Left, Top position where the crop-box will be placed, relatively to the Top-Left corner of the image.
  • There are two buttons that control the relationship between the Width and Height text-boxes: Constrain proportions and Swap dimensions. The first is used to lock the ratio between the width and height and keep the aspect ratio. By default the aspect ratio is preserved.
    The second gives the possibility to easily exchange the values of the width and height.
  • DefaultCS.aspx
  • DefaultCS.aspx.cs
<%@ Page Language="C#" AutoEventWireup="true" Inherits="Telerik.Web.Examples.ImageEditor.Crop.DefaultCS"CodeFile="DefaultCS.aspx.cs"  %>

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link href="../../common/styles.css" rel="stylesheet" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <div class="demo-container size-wide">
        <telerik:RadImageEditor RenderMode="Lightweight" ID="RadImageEditor1" runat="server" ImageUrl="~/ImageEditor/images/hay.jpg" Width="790" Height="430px">
            <Tools>
                <telerik:ImageEditorToolGroup>
                    <telerik:ImageEditorToolStrip CommandName="Undo">
                    </telerik:ImageEditorToolStrip>
                    <telerik:ImageEditorToolStrip CommandName="Redo">
                    </telerik:ImageEditorToolStrip>
                    <telerik:ImageEditorToolSeparator></telerik:ImageEditorToolSeparator>
                    <telerik:ImageEditorTool CommandName="Crop"></telerik:ImageEditorTool>
                </telerik:ImageEditorToolGroup>
            </Tools>
        </telerik:RadImageEditor>
    </div>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance