Save Reset in WPF Image Editor (SfImageEditor)

20 Oct 20204 minutes to read

Image can be saved along with the changes. An image can be saved in the following two ways:

  • Saving an image using the toolbar.
  • Saving an image programmatically.

Saving an image using the toolbar

To save an image, click the save icon in the toolbar. You can choose the desired location from the save file dialog to save the edited image.

Saving an image programmatically

An image can be saved programmatically using the Save method in image editor as follows. The save method takes the following three parameters:

  • ImageFormat - Specifies the format in which image has to be saved.

  • Size - Saves the image in the specified size.

  • FilePath - Specifies the location in which image has to be saved.

editor.Save();

Image size specification

You can save an image with the required size by specifying the size parameter in the save method as follows.

editor.Save(null, new Size(750,500), null);

Image location

Image can be saved at the specified location as demonstrated in the following code.

editor.Save(null, default(Size), @"E:\Images\");

Image format

You can specify the format, in which image has to be saved as the parameter in Save method as follows.

editor.Save("png", default(Size), null);

Reset

To reset the changes made, click the Reset icon in the toolbar. To programmatically reset, use the following code.

editor.Reset();

Events

Saving an events

Image editor has the following two events:

Image saving

This event occurs before the image is saved to the destination location. ImageSavingEventArgs is the parameter. This argument contains the following two properties:

  • Cancel - Cancels the saving functionality.
  • Stream - Stream of the image that is going to be saved.
  • FileName - You can save the image in the specified name using the ImageSaving event.

Hence, you can control the saving using the Cancel property, and you can also access the stream as needed.

The following code cancels the default saving and saves the stream in the specified location.

<editor:SfImageEditor x:Name="editor" ImageSaving="editor_ImageSaving" ImageSource="Assets\Buldingimage.jpeg">
        </editor:SfImageEditor>
private void Editor_ImageSaving(object sender, ImageSavingEventArgs args)
        {
            args.Cancel = true; 
            FileStream stream = new FileStream(@"E:\Images\Resized.jpg", FileMode.Create);
            args.Stream.CopyTo(stream);
            stream.Seek(0, 0);
            args.FileName = "SavedImage";
        }

Image saved

This event occurs after the image has been saved to the destination location. The ImageSavedEventArgs will be the parameter. This parameter contains the Location property, which specifies the location in which image is saved.

private void Editor_ImageSaved(object sender, ImageSavedEventArgs args)
        {
            string filePath = args.Location;
        }

Reset events

The Reset functionality has the following two events:

Begin reset

This event occurs before resetting the changes. Hence, you can control the reset operation using the Cancel property in the BeginResetEventArgs.

private void Editor_BeginReset(object sender, BeginResetEventArgs e)
        {
            e.Cancel = true;
        }

End reset

This event occurs after the reset function has been completed.

private void Editor_EndReset(object sender, EndResetEventArgs e)
        {

        }

See also

How to capture and save signature using the image editor