Jump to navigation

Poupou's Corner of the Web

Looking for perfect security? Try a wireless brick.
Otherwise you may find some unperfect stuff here...

Weblog

Metafiles

Today the biggest, API wise, missing feature in libgdiplus are metafiles. Just like the handling of icons, metafile support exists in several ways in GDI+.

First we have the System.Drawing.Imaging.Metafile class, which supports both the older (16bits) WMF and the newer (32bits) EMF formats (each one having some subformats to deal with). Unlike the Icon class Metafile inherits from the System.Drawing.Image class, so you can use them pretty much like any Bitmap, including the 30 overloads of Graphics.DrawImage method.

Beside being very badly documented, this class design is also kind of surprising. It has nearly different 40 constructors to allow playing or recording a metafile. Add to that (only) seven methods, including five overloads to get the metafile's header MetafileHeader, one to get the HENHMETAFILE handle and one to replay records (not the whole metafile) and you complete the class.

Then we have two separate codecs, one for WMF and one for EMF. Both are decoders only, which means they get used for Image.From[File|Stream] but won't help you to save a metafile, e.g. Image.Save.

Enough text for now...

 
MS System.Drawing/GDI+ versus Mono/Libgdiplus

The Mono's picture was generated using a very limited WMF codec/parser, it doesn't call functions for half of the metafile commands (e.g. in this picture we're visually missing MoveTo and Arc). The next step is to review all existing *Image* code and, in most case, adapted not to use the bitmap data directly (e.g. width). Once this is done, I'll resume work on the WMF parser, then the EMF parser and post pictures from time to time.

P.S. I have not looked much to find free WMF and EMF(+) metafile samples but if you have some free ones (this worked so well for the Vista icons, thanks to everyone :-) I'd like them for the test suite. Right now they don't need to be torture tests ;-). Thanks!


2/20/2007 08:52:50 | Comments

The views expressed on this website/weblog are mine alone and do not necessarily reflect the views of my employer.