HighTechTalks DotNet Forums  

Metafile fails to exit recording mode

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Metafile fails to exit recording mode in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Birkeland (Offline)
Junior Member
 
Posts: 3
Join Date: Jan 2007

Default Metafile fails to exit recording mode - 01-15-2007 , 07:16 AM






Hi

I have a small pice of code that creates a metafile, writes one line of text and returns the metafile.

This only crashes when it is called more than around 29028-29039 times.
Trying to read any of the properties of the metafile results in a "Parameter is not valid." error. This is the same behavior as the metaimage usually have before the graphics object is disposed.

From MSDN:
"The recording of the metafile ends when that Graphics object is deleted or goes out of scope."
This seems to stop function....


My code:

Private Function getMetaWithText(ByVal gTarget As Graphics, ByVal s As String, ByVal font As Font) As Metafile
Dim hRefDC As System.IntPtr = gTarget.GetHdc()
Dim meta As New Metafile(hRefDC, EmfType.EmfPlusOnly)

Using g As Graphics = Graphics.FromImage(meta), b As New SolidBrush(Color.Black)
g.DrawString(s, font, b, 0, 0)
End Using

gTarget.ReleaseHdc(hRefDC)

Return meta
End Function

The Using construct guarantees that the graphics object defined within the Using block will be disposed of after the block.

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.