Jump to content
Software FX Community

Export Chart to Metafile format in Stream


Bertrand_D
 Share

Recommended Posts

Hi,

I want to export a Winform chart to a .png or .gif file format, using Metafile first (rather than bitmap) to ensure a better quality of the output image. Also, I am working with MemoryStream rather than saving files on disk. I have the following Chart Exportation crashing, could you pelase help? (it works fine when I save files to disk, not with streams)

private

static MemoryStream ExportChartToStream(ChartFX.WinForms.Chart chart){  MemoryStream imgStream = new MemoryStream();  MemoryStream metafileStream = new MemoryStream();  chart.Export(FileFormat.Metafile, metafileStream);  var meta = new Metafile(metafileStream);  <----------- Generic Error occured in GDI+ ...  meta.Save(imgStream, ImageFormat.Png);  return imgStream;}

Thank you,

Bertrand

Link to comment
Share on other sites

I dont have an answer to your question, but I might have a better way if all you are trying to do is export charts in higher quality. Try the following:

  int desiredDPI = 300;   Rectangle r = new Rectangle(0, 0, (chart1.Width * desiredDPI) / 96, (chart1.Height * desiredDPI) / 96);   Bitmap bmp = new Bitmap (r.Width, r.Height);   bmp.SetResolution(desiredDPI, desiredDPI);   Graphics g = Graphics .FromImage(bmp);   chart1.Paint(g, r, PaintStyles .Background | PaintStyles .Border | PaintStyles .Print);   bmp.Save(@"c:\temp\cfx.png", ImageFormat.Png);   g.Dispose();   bmp.Dispose(); 

Link to comment
Share on other sites

Hi,

 

Thank you for your answer.I have been trying to use your method but i am getting a smaller graph in the Rectangle with a lower definition.I am finnally using the basic following code (simplier and shorter) providing a very good quality of the chart.

 

private MemoryStream ExportChartToStream(ChartFX.WinForms.Chart chart) {   try   {   MemoryStream imgStream = new MemoryStream();   chart.Export(FileFormat.Bitmap, imgStream);   return imgStream;   }   catch (Exception e)   {   throw new Exception ("Error in ExportChartToStream()", e);   }

}

Thanks for your help.Bertrand

Link to comment
Share on other sites

  • 4 months later...
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...