WPF export chart to Metafile

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
MVuser2
Newbie
Newbie
Posts: 9
Joined: Wed Jun 29, 2011 12:00 am

WPF export chart to Metafile

Post by MVuser2 » Mon Jun 25, 2012 3:39 pm

Hi,

i understand that in the WPF version we cannot export the chart to metafile.
we had some problems at the past with other formats(most of them were related to the aspect of the picture).

which options i have in WPF teechart and which one is the most close to metafile?

p.s,
it should be a type that can be shown later on on a picturebox.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: WPF export chart to Metafile

Post by Sandra » Tue Jun 26, 2012 3:09 pm

Hello MVuser2,


My only suggestion to work with metafiles in wpf is export as a bitmap as explain in this link to achieve work with a metafile.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

MVUser6
Newbie
Newbie
Posts: 30
Joined: Wed Jul 11, 2012 12:00 am

Re: WPF export chart to Metafile

Post by MVUser6 » Mon Aug 20, 2012 10:42 am

Hi,

the problem persist.

with WPF bitmap(and other image formats) there is Pixelization of the picture. it doesn't matter that afterwards i'm converting it to a metafile, because it already Pixelizated.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: WPF export chart to Metafile

Post by Narcís » Tue Aug 21, 2012 1:15 pm

Hi MVUser6,

I'm using the code snippet below which produces the attached bitmap and copies it in metafile format in the clipboard. I don't think any of the resultant images suffers from aliasing. Could you please give us more detailed information about the problem you are experiencing and modify the code below so that we can reproduce the problem here?

Code: Select all

  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();
      InitializeChart();
    }

    private void InitializeChart()
    {
      tChart1.Series.Add(new Steema.TeeChart.WPF.Styles.Line()).FillSampleValues();

      string fileName = @"c:\temp\wpf.bmp";
      tChart1.Export.Image.Bitmap.Width = 800;
      tChart1.Export.Image.Bitmap.Height = 600;
      tChart1.Export.Image.Bitmap.Save(fileName);      

      System.Drawing.Bitmap gdiBitmap = null;
      System.IO.MemoryStream metafileStream = null;

      try
      {
        gdiBitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(fileName);
        metafileStream = MakeMetafileStream(gdiBitmap);

        var dataObj = new DataObject();
        dataObj.SetData(DataFormats.Bitmap, gdiBitmap);
        dataObj.SetData(DataFormats.EnhancedMetafile, metafileStream);
        Clipboard.SetDataObject(dataObj, true);
      }
      catch
      { }
      finally
      {
        if (gdiBitmap != null)
        { gdiBitmap.Dispose(); }
        if (metafileStream != null)
        { metafileStream.Dispose(); }
      }
    }

    private static System.IO.MemoryStream MakeMetafileStream(System.Drawing.Bitmap image)
    {
      System.Drawing.Graphics graphics = null;
      System.Drawing.Imaging.Metafile metafile = null;
      var stream = new System.IO.MemoryStream();
      try
      {
        using (graphics = System.Drawing.Graphics.FromImage(image))
        {
          var hdc = graphics.GetHdc();
          metafile = new System.Drawing.Imaging.Metafile(stream, hdc);
          graphics.ReleaseHdc(hdc);
        }
        using (graphics = System.Drawing.Graphics.FromImage(metafile))
        { graphics.DrawImage(image, 0, 0); }
      }
      finally
      {
        if (graphics != null)
        { graphics.Dispose(); }
        if (metafile != null)
        { metafile.Dispose(); }
      }
      return stream;
    }

  }
Thanks in advance.
Attachments
wpf.zip
(73.68 KiB) Downloaded 471 times
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply