Problem with metafile export

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Holger Persch
Newbie
Newbie
Posts: 8
Joined: Mon Mar 14, 2005 5:00 am
Location: Germany

Problem with metafile export

Post by Holger Persch » Thu Apr 21, 2005 10:44 am

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?
Best regards
Holger

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

Post by Narcís » Thu Apr 21, 2005 11:54 am

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);
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

Holger Persch
Newbie
Newbie
Posts: 8
Joined: Mon Mar 14, 2005 5:00 am
Location: Germany

Post by Holger Persch » Thu Apr 21, 2005 12:08 pm

Hi Narcís,

Great, that's it.
Many thanks!!!
Best regards
Holger

Post Reply