This is a migrated thread and some comments may be shown as answers.

Export image in ImageEditor in code behind ?

1 Answer 87 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Olivier Constance
Top achievements
Rank 1
Olivier Constance asked on 13 Mar 2013, 07:44 AM
Hi,

I use the WPF Q1 2012 SP1.

I just want to export/save the image contained in the ImageEditor with my own method.

What is the better way to do that ?

Thanks for your help.

1 Answer, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 15 Mar 2013, 02:05 PM
Hi Olivier,

You can use the available format providers to encode the images in a specific format – e.g. BMP or PNG - in the same way as illustrated in the AddImageInEditor method in the documentation. Here is an example:
   private void ExportImageInEditor()
      {
          SaveFileDialog sfd = new SaveFileDialog();
          sfd.Filter = "PNG Images (*.png)|*.png|BMP Images (*.bmp)|*.bmp;*|All images|*.*";
          sfd.FilterIndex = 3;
          if (sfd.ShowDialog() == true)
          {
              string extension = System.IO.Path.GetExtension(sfd.SafeFileName).ToLower();
              Stream stream = sfd.OpenFile();
              IImageFormatProvider formatProvider = ImageFormatProviderManager.GetFormatProviderByExtension(extension);
              if (formatProvider == null)
              {
                  StringBuilder sb = new StringBuilder();
                  sb.Append("Unable to find format provider for extension: ")
                    .Append(extension).Append(" .");
                  return;
              }
              else
              {
                  using (stream)
                  {
                  formatProvider.Export(this.imageEditorUI.Image, stream);
                  }
              }
          }
     
}

Note that if you have some uncommitted change in the image and you want it to be present in the exported file, you should commit it programmatically:

this.imageEditorUI.ImageEditor.CommitTool();


Kind regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ImageEditor
Asked by
Olivier Constance
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Share this question
or