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=''>
<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" />
    <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">
                    <telerik:ImageEditorToolStrip CommandName="Undo">
                    <telerik:ImageEditorToolStrip CommandName="Redo">
                    <telerik:ImageEditorTool CommandName="Crop"></telerik:ImageEditorTool>

Support & Learning Resources

Find Assistance