Generate GDI+ source code by enumerating a WMF file.

Posted on 2009-02-22
Medium Priority
Last Modified: 2012-05-06
Is there anyway to create a program that can generate vb.net GDI+ source code from a windows metafile or an enhanced metafile? I was thinking it would be possible through calling Graphics.EnumerateMetafile, but I don't know if there was a way to convert the metafile records to generate equivilant GDI+ code.
Any ideas?
Question by:mavcosys
  • 2
  • 2
LVL 41

Expert Comment

ID: 23715690
I'm not following you.... tell us what you're trying do (rather than the technique you want to use)

Author Comment

ID: 23751938
I apologize for my delay in responding to your question.

What I would like to be able to do is design the graphics in a graphics editor such as Adobe Illustrator, export my art as a vector art file, and have a program generate vb.net code (DrawLine, DrawEllipse, .. and such) so that I can animate different parts of the drawing with code.

A very simple example would be that I go into Illustrator and draw a circle with a red fill. Then I save the art as a WMF or an EMF. Then I run my code generator app which would read the file, and output a text file with the vb.net code: graphics.DrawEllipse(...).

Then in the application I am building, I can paste the code that was generated, and maybe change the fill color based on any number of parameters.

On a much larger scale, this would allow for me to create complex art drawings in a graphics editor instead of having to try and develop all the code for the graphics. Then I could generate the vb.net code from that vector art file, and have the ability to modify pieces of that code for animating the graphics.

Thanks for your time, if I need to clarify anything further, please let me know!
LVL 41

Accepted Solution

graye earned 2000 total points
ID: 23752495
No, I've never heard of anything exactly like that...
However, that concept is part of the idea behind the new the XAML file format.   You create a graphic using a member of the Microsoft Expression Suite (or some other graphics application) and save the graphics as a XAML file.  Then you can open the XAML file in Visual Studio for further processing or for run-time changes.
But, it wont generate VB.Net code for you...

Author Comment

ID: 23752590
That could be quite useful! Only usable in a WPF application though right?

Here is an example of what I was trying to accomplish, only it generates c++ code:
I also found this site that shows how to enumerate through a wmf file, and allows you to skip over parts of the drawing process:
Enumerate WMF File
Which is why it might be possible to take it one step further and generate the .net code for each step, but the only way I can see that being possible would be to write a class that detected the type of record, and extract the metadata, and use a select case to correlate the record type to a specific graphics object method. And I wasn't sure if that was even possible!

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question