EMF File Format Issue

Dec 17, 2009 at 8:52 PM

I am attempting to use the EMF control to display some EMF files in a project I'm working on. When loading the EMF files, it fails to pass the format validation and indicates they are not EMF files.  I was confident my files were valid EMFs, so I decided to download the source and start digging....

I got the Sample app up and running and it displays the included sample WMF files just fine. So, I then attempted to get it to display my EMF file, but it fails to display it. Further digging reveals the offending piece of code...

In the EmfConvert class, the ToXaml method attempts to read the first 40 bytes of the stream, and then compares the first 4 bytes of that header to the value 0x9ac6cdd7. If it fails this comparison, it indicates the file is not an EMF file and throws an exception. 

           byte[] header;

            if (!ByteUtility.TryRead(input, 40, out header) || ReadUInt32(header, 0) != 0x9ac6cdd7) {
                throw new ConverterException(Resources.ExceptionNoEmfStream);

I opened my known EMF files in a hex editor and confirmed they conform to the EMF spec, as published by MS, but have vastly different headers. Near as I can tell, netiher of these file formats should ever begin with this value. Yet the sample files incuded with the source code are named with a .wmf extention and they do have this mistry value in the header. 

WMF - http://download.microsoft.com/download/a/e/6/ae6e4142-aa58-45c6-8dcf-a657e5900cd3/%5BMS-WMF%5D.pdf
EMF - http://download.microsoft.com/download/a/e/6/ae6e4142-aa58-45c6-8dcf-a657e5900cd3/%5BMS-EMF%5D.pdf

Does anyone know what format of file this control is actualy trying to read? Or better yet, does anyone know of a way to display EMF files in a Silverlight 3 app natively?


Dec 17, 2009 at 9:17 PM
Edited Dec 17, 2009 at 9:18 PM

OK, after reading the WMF spec further, I have determined that the EMF control is reading a special type of WMF file; one that has a Placeable MetaFile header. It doeasn't attempt to read true EMF files at all.