Page 1 of 1

Problem with metafile export

Posted: Thu Apr 21, 2005 10:44 am
by 8731282
Hi,

I'm trying to put a chart into a report (Report Sharp Shooter) by exporting it into a metafile, but unfortunately the following code

Code: Select all

			Steema.TeeChart.Export.MetafileFormat mff = this.tChart1.Export.Image.Metafile;
			mff.Enhanced = true;
			mff.Width = 800;
			mff.Height = 600;						
			
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			mff.Save(stream);

			System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
ends up with an exception:

An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll

Additional information: Invalid parameter used.


Unhandled Exception: System.ArgumentException: Invalid parameter used.
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at TeeChartMetaFileExport.Form1.button2_Click(Object sender, EventArgs e) in d:\projects .net\teechartmetafileexport\form1.cs:line 227


It makes no difference if a MemoryStream or a FileStream is used. If the metafile is stored to the disk then it can be opend with the "Windows Image Viewer" without any problems.

Any help or workaround available?

Posted: Thu Apr 21, 2005 11:54 am
by narcis
Hi Holger,

Yes, you should reposition the stream pointer at the beginning of the stream doing stream.position=0 as in the snippet below:

Code: Select all

			Steema.TeeChart.Export.MetafileFormat mff = this.tChart1.Export.Image.Metafile; 
			mff.Enhanced = true; 
			mff.Width = 800; 
			mff.Height = 600;                   
          
			System.IO.MemoryStream stream = new System.IO.MemoryStream(); 
			mff.Save(stream); 
			stream.Position=0;
			
			System.Drawing.Image image = System.Drawing.Image.FromStream(stream);

Posted: Thu Apr 21, 2005 12:08 pm
by 8731282
Hi NarcĂ­s,

Great, that's it.
Many thanks!!!