Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9946


Ignore:
Timestamp:
09/11/13 14:34:25 (11 years ago)
Author:
bburlacu
Message:

#2107: Fixed chart export to emf format.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ImageExportDialog.cs

    r9520 r9946  
    6868        Width = 305;
    6969        Height = 625;
    70       } finally { SuppressEvents = false; }
     70      }
     71      finally { SuppressEvents = false; }
    7172      #endregion
    7273    }
     
    9394        if (workingChart.Legends.Count == 0) legendFontSizeComboBox.Text = "6";
    9495        else legendFontSizeComboBox.Text = workingChart.Legends[0].Font.SizeInPoints.ToString();
    95       } finally {
     96      }
     97      finally {
    9698        SuppressEvents = false;
    9799      }
     
    209211          }
    210212        }
    211       } finally { SuppressEvents = false; }
     213      }
     214      finally { SuppressEvents = false; }
    212215      base.OnShown(e);
    213216
     
    438441      float height;
    439442      GetImageParameters(out dpi, out width, out height);
    440 
    441443      var image = new Bitmap((int)Math.Round(width), (int)Math.Round(height));
    442444      image.SetResolution(dpi, dpi);
    443       using (var graphics = Graphics.FromImage(image)) {
    444         workingChart.Printing.PrintPaint(graphics, new Rectangle(0, 0, image.Width, image.Height));
    445       }
    446 
    447445      if (titleTextBox.Text.Trim() != String.Empty) saveFileDialog.FileName = titleTextBox.Text.Trim();
    448446      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
    449447        var format = ImageFormat.Bmp;
    450448        var filename = saveFileDialog.FileName.ToLower();
    451         if (filename.EndsWith("jpg")) {
    452           format = ImageFormat.Jpeg;
    453         } else if (filename.EndsWith("emf")) {
    454           format = ImageFormat.Emf;
    455         } else if (filename.EndsWith("gif")) {
    456           format = ImageFormat.Gif;
    457         } else if (filename.EndsWith("png")) {
    458           format = ImageFormat.Png;
    459         } else if (filename.EndsWith("tif")) {
    460           format = ImageFormat.Tiff;
    461         }
    462         image.Save(saveFileDialog.FileName, format);
    463       }
    464 
     449        if (filename.EndsWith("emf")) {
     450          using (var graphics = Graphics.FromImage(image)) {
     451            var metafile = new Metafile(filename, graphics.GetHdc());
     452            graphics.ReleaseHdc();
     453            using (var g = Graphics.FromImage(metafile)) {
     454              workingChart.Printing.PrintPaint(g, new Rectangle(0, 0, image.Width, image.Height));
     455            }
     456            metafile.Dispose();
     457          }
     458        } else {
     459          using (var graphics = Graphics.FromImage(image)) {
     460            workingChart.Printing.PrintPaint(graphics, new Rectangle(0, 0, image.Width, image.Height));
     461          }
     462          if (filename.EndsWith("jpg")) {
     463            format = ImageFormat.Jpeg;
     464          } else if (filename.EndsWith("gif")) {
     465            format = ImageFormat.Gif;
     466          } else if (filename.EndsWith("png")) {
     467            format = ImageFormat.Png;
     468          } else if (filename.EndsWith("tif")) {
     469            format = ImageFormat.Tiff;
     470          }
     471          image.Save(saveFileDialog.FileName, format);
     472        }
     473      }
    465474      image.Dispose();
    466 
    467475      Cleanup();
    468476    }
Note: See TracChangeset for help on using the changeset viewer.