Export image in ImageEditor in code behind ?

2 posts, 0 answers
  1. Olivier Constance
    Olivier Constance avatar
    6 posts
    Member since:
    Jul 2009

    Posted 13 Mar 2013 Link to this post


    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.
  2. Iva Toteva
    Iva Toteva avatar
    1319 posts

    Posted 15 Mar 2013 Link to this post

    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(" .");
                      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:


    Kind regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top