Articles in this section
Category / Section

How to retrieve a edited image as a stream in WPF Image Editor?

2 mins read

This section explains how to retrieve the stream of the edited image. This retrieved stream can be used for exporting functions.

To retrieve the stream of the edited image, follow the below steps.

Step 1: Initialize the image editor.

XAML

    <editor:SfImageEditor x:Name="editor" 
                               ImageSource="Assets\RoadView.jpeg" >
        </editor:SfImageEditor>

 

Step 2:  By default, on clicking the save icon in the toolbar, picker will be opened to pick the desired the saving location, to hide this functionality invoke the ToolbarItemSelected event and set Cancel to true for the save item alone in the arguments as shown in the below snippet.

XAML

  <editor:SfImageEditor.ToolbarSettings>
                <editor:ToolbarSettings ToolbarItemSelected="ToolbarSettings_ToolbarItemSelected"></editor:ToolbarSettings>
            </editor:SfImageEditor.ToolbarSettings>

C#

        /// <summary>
        /// Invoked when toolbar item is clicked.
        /// </summary>
        /// <param name="sender">Toolbar item</param>
        /// <param name="e">event arguments</param>
        private void ToolbarSettings_ToolbarItemSelected(object sender, ToolbarItemSelectedEventArgs e)
        {
            /// Cancel the default functionality only for save icon.
            if (e.ToolbarItem.Name == "Save")
            {
                e.Cancel = true;
                editor.Save();
            }
        }

 

Step 3: Invoke ImageSaving event to retrieve the current stream of the edited image as in the below snippet.

XAML

   <editor:SfImageEditor x:Name="editor" ImageSaving="Editor_ImageSaving" 
>
        </editor:SfImageEditor>
 

C#

        /// <summary>
        /// Invoked before image getting saved.
        /// </summary>
        /// <param name="sender">Image editor</param>
        /// <param name="e">event arguments</param>
        private void Editor_ImageSaving(object sender, ImageSavingEventArgs e)
        {
            e.Cancel = true;
            e.Stream.Seek(0, 0);
            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.BeginInit();
            bitmapImage.StreamSource = e.Stream;
            bitmapImage.EndInit();
            image.Source = bitmapImage;
        }
 

 

You can use the retrieved stream for exporting purpose. In this demonstration retrieved stream is set to source for Image control on the right side as shown in the below image.

Screenshot:

Retrieve the stream

Sample for retrieving the stream of the edited image can be referred here.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied