Generate GDI+ source code by enumerating a WMF file.

Posted on 2009-02-22
Last Modified: 2012-05-06
Is there anyway to create a program that can generate 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
    LVL 41

    Expert Comment

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

    Author Comment

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

    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

    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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    This video discusses moving either the default database or any database to a new volume.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now