Skip to content

Commit e4b84de

Browse files
committed
824314: Image Editor New UG Sample
1 parent 75c5214 commit e4b84de

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

blazor/image-editor/open-save.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ You can utilize the ‘[`FileOpenEventArgs`](https://help.syncfusion.com/cr/blaz
199199
200200
@code {
201201
SfImageEditor ImageEditor;
202-
private string base64String;
203202
204203
private async void OpenAsync()
205204
{
@@ -362,7 +361,7 @@ User can utilize the ‘[`BeforeSave`](https://help.syncfusion.com/cr/blazor/Syn
362361
private async void SavedAsync()
363362
{
364363
var Shapes = await ImageEditor.GetShapeSettingsAsync();
365-
await ImageEditor.DeleteShapeAsync(shapes[shapes.length - 1].id);
364+
await ImageEditor.DeleteShapeAsync(Shapes[Shapes.length - 1].id);
366365
}
367366
}
368367
```
@@ -387,7 +386,33 @@ User can leverage the [`Toolbar`](https://help.syncfusion.com/cr/blazor/Syncfusi
387386

388387
### Prevent default save option and save the image to specific location
389388

390-
User can make use of the [`BeforeSave`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.ImageEditor.SaveEventArgs.html) event, which triggers just before the image is downloaded, to override the default save option by setting `args.cancel` to true. Afterward, you can utilize the [`GetImageDataAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.ImageEditor.SfImageEditor.html#Syncfusion_Blazor_ImageEditor_SfImageEditor_GetImageDataAsync) method to retrieve the current image data and convert it into a format like `byte[]`, `blob`, or `base64` for further processing. This gives you greater flexibility in handling the image data.
389+
User can make use of the [`BeforeSave`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.ImageEditor.SaveEventArgs.html) event, which triggers just before the image is downloaded, to override the default save option by setting `args.cancel` to true. Afterward, you can utilize the [`GetImageDataAsync`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.ImageEditor.SfImageEditor.html#Syncfusion_Blazor_ImageEditor_SfImageEditor_GetImageDataAsync) method to retrieve the current image data and convert it into a format like `byte[]`, `blob`, or `base64` for further processing. This gives you greater flexibility in handling the image data.
390+
391+
```cshtml
392+
@using Syncfusion.Blazor.ImageEditor
393+
@using System.IO
394+
395+
<div>
396+
<SfImageEditor @ref="ImageEditor" Height="400px" Width="500px">
397+
<ImageEditorEvents Saving="OnBeforeSave"></ImageEditorEvents>
398+
</SfImageEditor>
399+
</div>
400+
401+
@code {
402+
private SfImageEditor ImageEditor;
403+
404+
private async Task OnBeforeSave(SaveEventArgs args)
405+
{
406+
args.Cancel = true;
407+
var imageData = await ImageEditor.GetImageDataUrlAsync();
408+
if (!string.IsNullOrEmpty(imageData) && imageData.Contains(","))
409+
{
410+
var base64Data = imageData.Split(',')[1];
411+
byte[] imageBytes = Convert.FromBase64String(base64Data);
412+
}
413+
}
414+
}
415+
```
391416

392417
## Events to handle Save Actions
393418

0 commit comments

Comments
 (0)