davidastle
asked on
Metafile problem
All i want to do is create a metafile.
This code:
System.Drawing.Imaging.Met afile m = new Metafile(@"C:\anywhere\any file.anyex tension");
Gives me an error. A messagebox pops up that says "A generic error has occurred in GDI+"
I can't even create a metafile from an imagestream.
What am I doing wrong?
This code:
System.Drawing.Imaging.Met
Gives me an error. A messagebox pops up that says "A generic error has occurred in GDI+"
I can't even create a metafile from an imagestream.
What am I doing wrong?
Initializes a new instance of the Metafile class from the specified file name. .... is there actually a metafile there ?
ASKER
No... how do i make a metafile then? The msdn example at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdrawinggraphicsclassenumeratemetafiletopic2.asp just crashes when i run it giving the same "generic error has occurred in GDI+" error
ASKER
MSDN says that "A metafile contains records that describe a sequence of graphics operations that can be recorded (constructed) and played back (displayed). Not inheritable." Wonderful. Its hard to record any sequence of graphics operations when you cant create an instance of a metafile!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
notice the passing of the hDc
ASKER
Oh i get it. Most of the constructors for the metafile are you used for playback. If you want to make one for recording, you have to send in a device context to the graphics object that you want to record.
So now i want to create a metafile that records everything thats drawn in an OnPaint method.
When i try to save the metafile i create, it just gives another "generic error":
protected override void OnPaint(PaintEventArgs e)
{
if (createmetafile)
{
IntPtr hdc = e.Graphics.GetHdc();
this.myMeta = new Metafile(hdc, e.ClipRectangle);
createmetafile = false;
base.OnPaint (e);
e.Graphics.ReleaseHdc(hdc) ;
myMeta.Save(@"C:\a\MyMetaf ile.emf", ImageFormat.Emf);
}
else
base.OnPaint(e);
}
So now i want to create a metafile that records everything thats drawn in an OnPaint method.
When i try to save the metafile i create, it just gives another "generic error":
protected override void OnPaint(PaintEventArgs e)
{
if (createmetafile)
{
IntPtr hdc = e.Graphics.GetHdc();
this.myMeta = new Metafile(hdc, e.ClipRectangle);
createmetafile = false;
base.OnPaint (e);
e.Graphics.ReleaseHdc(hdc)
myMeta.Save(@"C:\a\MyMetaf
}
else
base.OnPaint(e);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
from looking around at some posts i don't think you can actually save a metafile via image.save ...it appears to "just do it"
not sure how reliable this info is but ...
not sure how reliable this info is but ...
In the above mentioned book see pp. 363 thru 370.
About saving...dunno.
I've never created metafiles...I just have a book that supposedly shows you how. :)
Good luck!
About saving...dunno.
I've never created metafiles...I just have a book that supposedly shows you how. :)
Good luck!
ASKER
Hmmm... well one last thing before I give you the points (i don't think i can expect a better answer). I already know managed directX so learning GDI seems like a step down... is it worth the time?
I always give one point to people when discussing the relative goodness of solutions ...
Sometimes a hammer is good, sometimes a radial saw is good. Learning new/different technologies is no different than a carpenter buying a new tool. You may run into a case where your current tool may not be the optimum one, however in practice always use the tool that you feel is best according to the restrictions placed upon the project (be they technological or time based).
Sometimes a hammer is good, sometimes a radial saw is good. Learning new/different technologies is no different than a carpenter buying a new tool. You may run into a case where your current tool may not be the optimum one, however in practice always use the tool that you feel is best according to the restrictions placed upon the project (be they technological or time based).
ASKER
OK ill buy the book! I'm going to keep this thread open for a few more days to see if anyone else has any ideas though.