Skip to content

Commit 9dfefc0

Browse files
committed
824314: Image Editor New UG Sample
1 parent d0d59bf commit 9dfefc0

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

blazor/image-editor/open-save.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,41 @@ builder.Services.AddServerSideBlazor().AddHubOptions(o => { o.MaximumReceiveMess
382382

383383
### Remove default Save button and add custom button to save the image to server
384384

385-
User can leverage the [`Toolbar`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.ImageEditor.SfImageEditor.html#Syncfusion_Blazor_ImageEditor_SfImageEditor_Toolbar) property to replace the default save button with a custom one. By doing so, you can use the [`GetImageDataUrlAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.ImageEditor.SfImageEditor.html#Syncfusion_Blazor_ImageEditor_SfImageEditor_GetImageDataUrlAsync) method to retrieve the image data, convert it to base64 format, and then save it to the server. This approach gives you more control over the image-saving process. 
385+
User can leverage the [`Toolbar`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.ImageEditor.SfImageEditor.html#Syncfusion_Blazor_ImageEditor_SfImageEditor_Toolbar) property to replace the default save button with a custom one. By doing so, you can use the [`GetImageDataUrlAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.ImageEditor.SfImageEditor.html#Syncfusion_Blazor_ImageEditor_SfImageEditor_GetImageDataUrlAsync) method to retrieve the image data, convert it to base64 format, and then save it to the server. This approach gives you more control over the image-saving process.
386+
387+
```cshtml
388+
@using Syncfusion.Blazor.ImageEditor
389+
@using Syncfusion.Blazor.Navigations
390+
391+
<div>
392+
<SfImageEditor @ref="ImageEditor" Height="400px" Width="500px" Toolbar="@customToolbar">
393+
</SfImageEditor>
394+
<button @onclick="SaveImage">Save to Server</button>
395+
</div>
396+
397+
@code {
398+
private SfImageEditor ImageEditor;
399+
400+
// Define the custom toolbar items
401+
private List<ImageEditorToolbarItemModel> customToolbar = new List<ImageEditorToolbarItemModel>()
402+
{
403+
new ImageEditorToolbarItemModel { Name = "Zoom" },
404+
new ImageEditorToolbarItemModel { Name = "Annotation" },
405+
new ImageEditorToolbarItemModel { Name = "Filter" },
406+
new ImageEditorToolbarItemModel { Name = "Crop" },
407+
new ImageEditorToolbarItemModel { Text = "Rotate", TooltipText = "Rotate", Align = ItemAlign.Center }
408+
};
409+
private async Task SaveImage()
410+
{
411+
var imageData = await ImageEditor.GetImageDataUrlAsync();
412+
if (!string.IsNullOrEmpty(imageData) && imageData.Contains(","))
413+
{
414+
var base64Data = imageData.Split(',')[1];
415+
byte[] imageBytes = Convert.FromBase64String(base64Data);
416+
}
417+
}
418+
}
419+
```
386420

387421
### Prevent default save option and save the image to specific location
388422

0 commit comments

Comments
 (0)