Getting Started with Blazor Image Editor Component in Web App
13 Oct 20257 minutes to read
This section explains how to include the Blazor Image Editor component in a Blazor Web App using Visual Studio or Visual Studio Code.
To get started quickly with the Blazor Image Editor component, refer to this video or the GitHub sample:
Prerequisites
Create a new Blazor Web App in Visual Studio
Create a Blazor Web App using Visual Studio 2022 via Microsoft Templates or the Syncfusion® Blazor Extension.
Configure the corresponding Interactive render mode and Interactivity location while creating the Blazor Web App.
Install Syncfusion® Blazor ImageEditor and Themes NuGet in the Blazor Web App
To add the Blazor Image Editor component, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), then search for and install Syncfusion.Blazor.ImageEditor and Syncfusion.Blazor.Themes.
When using WebAssembly or Auto render modes in a Blazor Web App, install Syncfusion® Blazor component NuGet packages in the client project.
Alternatively, use the following package manager commands to install the packages.
Install-Package Syncfusion.Blazor.ImageEditor -Version 31.2.2
Install-Package Syncfusion.Blazor.Themes -Version 31.2.2NOTE
Syncfusion® Blazor components are available on nuget.org. Refer to the NuGet packages topic for the list of available packages and component details.
Prerequisites
Create a new Blazor Web App in Visual Studio Code
Create a Blazor Web App using Visual Studio Code via Microsoft Templates or the Syncfusion® Blazor Extension.
Configure the corresponding Interactive render mode and Interactivity location while creating the Blazor Web App.
For example, in a Blazor Web App with the Auto interactive render mode, use the following commands.
dotnet new blazor -o BlazorWebApp -int Auto
cd BlazorWebApp
cd BlazorWebApp.ClientNOTE
For more information on creating a Blazor Web App with various interactive modes and locations, refer to this link.
Install Syncfusion® Blazor ImageEditor and Themes NuGet in the App
When using WebAssembly or Auto render modes in a Blazor Web App, install Syncfusion® Blazor component NuGet packages in the client project.
- Press Ctrl+` to open the integrated terminal in Visual Studio Code.
- Ensure the current directory is the project root where the
.csprojfile is located. - Run the following commands to install Syncfusion.Blazor.ImageEditor and Syncfusion.Blazor.Themes and ensure all dependencies are restored.
dotnet add package Syncfusion.Blazor.ImageEditor -v 31.2.2
dotnet add package Syncfusion.Blazor.Themes -v 31.2.2
dotnet restoreNOTE
Syncfusion® Blazor components are available on nuget.org. Refer to the NuGet packages topic for the list of available packages and component details.
Register Syncfusion® Blazor Service
| Interactive Render Mode | Description |
|---|---|
| WebAssembly or Auto | Open ~/_Imports.razor from the client project. |
| Server | Open ~/Components/_Imports.razor located in the Components folder. |
Import the Syncfusion.Blazor and Syncfusion.Blazor.ImageEditor namespaces.
@using Syncfusion.Blazor
@using Syncfusion.Blazor.ImageEditorNow, register the Syncfusion® Blazor Service in the ~/Program.cs file of the Blazor Web App.
If the Interactive Render Mode is set to WebAssembly or Auto, register the Syncfusion® Blazor service in both ~/Program.cs files of the Blazor Web App.
...
...
using Syncfusion.Blazor;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents();
builder.Services.AddSyncfusionBlazor();
var app = builder.Build();
.......
using Syncfusion.Blazor;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddSyncfusionBlazor();
await builder.Build().RunAsync();If the Interactive Render Mode is set to Server, the project contains a single ~/Program.cs file. In this case, register the Syncfusion® Blazor service only in that ~/Program.cs file.
...
using Syncfusion.Blazor;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddSyncfusionBlazor();
var app = builder.Build();
....Add stylesheet and script resources
The theme stylesheet and script can be accessed from NuGet through Static Web Assets. Include the stylesheet reference in the <head> section and the script reference at the end of the <body> in the ~/Components/App.razor file as shown below:
<head>
....
<link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
</head>
....
<body>
....
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
</body>NOTE
Refer to the Blazor Themes topic to discover various methods (Static Web Assets, CDN, and CRG) for referencing themes in a Blazor application. Also, refer to the Adding Script Reference topic to learn different approaches for adding script references.
Add Syncfusion® Blazor Image Editor component
Add the Syncfusion® Blazor Image Editor component in a .razor file inside the Pages folder. If the interactivity location is Per page/component in the web app, define a render mode at the top of the component, as follows:
| Interactivity location | RenderMode | Code |
|---|---|---|
| Per page/component | Auto | @rendermode InteractiveAuto |
| WebAssembly | @rendermode InteractiveWebAssembly | |
| Server | @rendermode InteractiveServer | |
| None | — |
NOTE
If the Interactivity Location is set to
Globaland the Render Mode is set toAuto,WebAssembly, orServer, the render mode is configured in theApp.razorfile by default.
@* desired render mode define here *@
@rendermode InteractiveAuto<SfImageEditor Height="500"></SfImageEditor>- Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to launch the application. This renders the Syncfusion® Blazor Image Editor component in the default web browser.