# Getting Started with the ImageEditor

This tutorial explains how to set up a basic Telerik UI for ASP.NET MVC ImageEditor and highlights the major steps in the configuration of the component.

You will initialize an ImageEditor and configure some of its options.

After completing this guide, you will achieve the following result:

![Sample Telerik UI for ASP.NET MVC ImageEditor](https://www.telerik.com/aspnet-mvc/documentation/assets/f3ad33ca00abd190d1145e45a52fc8fc/imageeditor-getting-started.png)

## Prerequisites

To successfully complete the tutorial, you need a project that is already configured to use the Telerik UI for ASP.NET MVC components:

* To create a new pre-configured project for the Telerik UI for ASP.NET MVC components, you can [use a project template](https://www.telerik.com/aspnet-mvc/documentation/getting-started-mvc/first-steps).

* To manually configure an existing project by using NuGet, see the [Adding Telerik UI through NuGet](https://www.telerik.com/aspnet-mvc/documentation/getting-started/setup-with-nuget).

## 1. Initialize the ImageEditor

Use the ImageEditor HtmlHelper  to add the component to a page:

* The `Name()` configuration method is mandatory as its value is used for the `id` and the `name` attributes of the ImageEditor element.
* The `SaveAs()` configuration allows you to set the name of the saved image file. You can also use it to configure a server proxy, which will stream the file to the end user.
* The `ImageUrl()` option enables you to load an initial image in the component.

```Razor HtmlHelper
@using Kendo.Mvc.UI

<h4>ImageEditor</h4>
@(Html.Kendo().ImageEditor()
    .Name("imageEditor")
    .Height(700)
    .SaveAs(s => s.FileName("image_edited.png"))
    .ImageUrl(@Url.Content("~/shared/images/photos/sample.jpg"))
)
```

## 2. (Optional) Configure the Toolbar

The ImageEditor comes with a set of default tools in its toolbar, but you can use the `.Toolbar()` configuration to declare only the tools you want.

The following example shows how to prevent the `open` and `crop` tools from appearing in the toolbar by excluding them from the list of declared tools.

```Razor HtmlHelper
@using Kendo.Mvc.UI

<h4>ImageEditor</h4>
@(Html.Kendo().ImageEditor()
    .Name("imageEditor")
    .Height(700)
    .SaveAs(s => s.FileName("image_edited.png"))
    .ImageUrl(@Url.Content("~/shared/images/photos/sample.jpg"))
    .Toolbar(toolbar=>toolbar.Items(i=> {
        i.Add().Name("save");
        i.Add().Name("resize");
        i.Add().Name("undo");
        i.Add().Name("redo");
        i.Add().Name("zoomIn");
        i.Add().Name("zoomOut");
        i.Add().Name("zoomDropdown");
    }))
)
```

## 3. Handle the ImageEditor Events

The ImageEditor exposes various [events](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/imageeditoreventbuilder) that you can handle and further customize the functionality of the component. In this example, you will use the `Error` event. This event helps you detect a failed attempt to load an image in the ImageEditor.

```Razor HtmlHelper
@using Kendo.Mvc.UI

<h4>ImageEditor</h4>
@(Html.Kendo().ImageEditor()
    .Name("imageEditor")
    .Height(700)
    .SaveAs(s => s.FileName("image_edited.png"))
    .ImageUrl(@Url.Content("~/shared/images/photos/sample.jpg"))
    .Events(ev => {
        ev.Error("onError");
    })
)
```

```JS script
<script>	
	function onError(e) {
		console.log("error");
	}
</script>
```

## 4. (Optional) Reference Existing ImageEditor Instances

Referencing existing instances allows you to build on top of their configuration. To reference an existing Gantt instance, use the [`jQuery.data()`](http://api.jquery.com/jQuery.data/) method:

1. Use the `id` attribute of the component instance to establish a reference.

   ```JS script
   <script>
       var imageEditorReference = $("#imageEditor").data("kendoImageEditor"); // imageEditorReference is a reference to the existing instance of the helper.
   </script>
   ```

2. Use the [ImageEditor client-side API](https://docs.telerik.com/kendo-ui/api/ui/imageeditor#methods) to control the behavior of the widget. In this example, you will programmatically execute the `ZoomImageEditorCommand` by using the `executeCommand` method.

   ```JS script
   <script>
       var imageEditorReference = $("#imageEditor").data("kendoImageEditor"); // imageEditorReference is a reference to the existing instance of the helper.
       imageEditorReference.executeCommand({ command: "ZoomImageEditorCommand", options: imageEditorReference.getZoomLevel() - 0.3 });
   </script>
   ```

For more information on referencing specific helper instances, see the [Methods and Events](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/helper-basics/events-and-methods) article.

## Next Steps

* [Configure the ImageEditor's Tools](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/imageeditor/tools)

## See Also

* [Using the API of the ImageEditor for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/imageeditor/api)
* [ImageEditor Client-Side API](https://docs.telerik.com/kendo-ui/api/ui/imageeditor)
* [Server-Side API of the ImageEditor](https://www.telerik.com/aspnet-mvc/documentation/api/imageeditor)
* [Knowledge Base Section](https://www.telerik.com/aspnet-mvc/documentation/knowledge-base)
