Page 1 of 1
WPF export chart to Metafile
Posted: Mon Jun 25, 2012 3:39 pm
by 15659704
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.
Re: WPF export chart to Metafile
Posted: Tue Jun 26, 2012 3:09 pm
by 10050769
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,
Re: WPF export chart to Metafile
Posted: Mon Aug 20, 2012 10:42 am
by 15662946
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.
Re: WPF export chart to Metafile
Posted: Tue Aug 21, 2012 1:15 pm
by narcis
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.