MetaFile Export and Windows 98

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
CitoTChartUser
Newbie
Newbie
Posts: 8
Joined: Mon Mar 01, 2004 5:00 am

MetaFile Export and Windows 98

Post by CitoTChartUser » Wed May 18, 2005 1:59 pm

Under Windows 2000 and XP I can succesfully export a Tchart to an image using:

Public Shared Function GetImage(ByVal chart As TChart) As Image
Dim strm As New IO.MemoryStream
With chart.Export.Image.Metafile
.Enhanced = True
.Width = chart.Width
.Height = chart.Height
.Save(strm)
strm.Position = 0
End With
Dim img As Image = Image.FromStream(strm)
strm.Flush()
strm.Close()
Return img
End Function

But running this code under Windows 98 Second edition the SAME program terminates with the following error:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidOperationException: The object is currently in use elsewhere.
at System.Drawing.Graphics.Dispose(Boolean disposing)
at System.Drawing.Graphics.Dispose()
at Steema.TeeChart.Export.MetafileFormat.SaveMetafile(Object FileOrStream)
at Steema.TeeChart.Export.MetafileFormat.Save(Stream stream)
at TchartTest.Form1.GetImage(TChart chart)
at TchartTest.Form1.Button1_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
TchartTest
Assembly Version: 1.0.1964.26268
Win32 Version: 1.0.1964.26268
CodeBase: file:///C:/TCHARTTEST.EXE
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
TeeChart
Assembly Version: 1.1.1879.21176
Win32 Version: 1.1.1879.21176
CodeBase: file:///C:/TeeChart.DLL
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.



Please tell us if this gets fixed!

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 May 19, 2005 8:44 am

Hi CitoTChartUser,

Can you create a metafile in Win 98 using .NET Framework native methods?

In case you were using dotted lines, it is only supported by windos NT, 2000, 2003 and XP.
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

CitoTChartUser
Newbie
Newbie
Posts: 8
Joined: Mon Mar 01, 2004 5:00 am

Post by CitoTChartUser » Thu May 19, 2005 1:01 pm

Yes we can create a metafile UNDER windows 98 using the .NET native methods.
We only use area's and 'standard lines' (not dotted, because they look too fat/ugly anyway).
This is a real problem for us, we are able to export to PNG under w98 (but the image looks too ugly, so we would like see this fixed)

Now something else: We can only export to metafile or PNG:

Why can't we [stream] export to JPEG, GIF or Bitmap (tested under Windows 2000 Prof. SP4), we always get the following error when we try to save or use the image

Code: Select all

  
Private Shared Function getImageJPEG(ByVal chart As TChart) As Image
    Dim strm As New IO.MemoryStream
    With chart.Export.Image.JPEG 'Or .Bitmap or .GIF
      .Width = chart.Width
      .Height = chart.Height
      .Save(strm)
      strm.Position = 0
    End With
    Dim img As Image = Image.FromStream(strm, True, True)
    strm.Flush()
    strm.Close()
    Return img
  End Function
Run-time exception thrown : System.Runtime.InteropServices.ExternalException - Er is een generieke fout opgetreden in GDI+. [translated: A generic error occured in GDI+]



Regards, Jan

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 May 19, 2005 1:46 pm

Hi Jan,

This problem can be solved commenting the MemoryStream.Close() line. This error is described at this Microsoft support article.

This code works fine:

Code: Select all

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Img As Image

        Img = getImageJPEG(TChart1)

        Img.Save("C:\test.jpg", Imaging.ImageFormat.Jpeg)
    End Sub

    Private Shared Function getImageJPEG(ByVal chart As Steema.TeeChart.TChart) As Image
        Dim strm As New IO.MemoryStream
        With chart.Export.Image.JPEG 'Or .Bitmap or .GIF 
            .Width = chart.Width
            .Height = chart.Height
            .Save(strm)
            strm.Position = 0
        End With
        Dim img As Image = Image.FromStream(strm, True, True)
        'strm.Close() 'problematic line
        Return img
    End Function
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

CitoTChartUser
Newbie
Newbie
Posts: 8
Joined: Mon Mar 01, 2004 5:00 am

Post by CitoTChartUser » Thu May 19, 2005 2:40 pm

Thanks Narcis,

Uncommenting 'strm.Close() 'problematic line solved it.

Did you find the creason why you can't export to MetaFile under windows 98 already?

Regards, Jan

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

Post by Narcís » Wed May 25, 2005 11:12 am

Hi Jan,

It's hard to tell as it can have several causes and a combination of things leading to them. However I've given you an alternative using .NET native methods to your newest thread regarding Win 98 Metafile export.
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