none
How can I load an EMF file into WPF?

    Question

  • Is there a way to load via code (C#) an EMF or WMF file and render it within WPF?

    Does WPF natively support this type?
    Seems it should since the WMF and EMF file types are vector based.


    Thursday, February 02, 2006 7:21 PM

Answers

  • WPF does not support the EMF and WMF image formats. These formats are more susceptible to security vulnerabilities than other image formats, so we do not intend to support them.

    However, the Windows Imaging Component, which is part of WPF, is extensible. A 3rd party could write a codec for EMF or WMF that's compatible with the Windows Imaging Component. Anyone who installs the codec will be able to display the corresponding image format in any WPF application or any application built on WIC. (Like any image format, if a security vulnerability is found, the codec will be disabled until a patch is released.)

    Monday, March 13, 2006 11:40 PM
  • Acrylic can open windows metafiles and convert it to xaml. 

    http://www.microsoft.com/products/expression/en/graphic_designer/default.aspx

    Wednesday, February 08, 2006 11:23 AM

All replies

  • Does anyone have an answer to this query?

    I would think Microsoft would support Metafiles since I beklieve they developed the WMF format.

    Anyone at Microsoft? Help!
    Tuesday, February 07, 2006 9:28 PM
  • Whenever I ask about these things the answers are:

    1) WPF does not support EMF/WMF, use WinForms interop.

    2) Office does not support XAML, use WPFHosting in your own control.

    Basically they are two separate groups that are not doing much to support interop scenarios beyond the bare minimum.  For the first release using WPF for Office related work is going to take deep expertise in both environments to be sucessful.

    Tuesday, February 07, 2006 11:33 PM
    Moderator
  • I know this isn't what you were looking for, but it's an interesting tool to watch. I suppose if you could get source for it, you could do something in semi-realtime.

    http://lab.aspitalia.com/lab.aspx?ID=15#eng

    This article discusses reasons why xaml is supposed to be much better then WMF:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnlong/html/avalongraphics.asp

    Still, good reasons aside, I'm very surprised MS didn't include their own WMF import helper.

    Jared

    Wednesday, February 08, 2006 5:03 AM
  • Acrylic can open windows metafiles and convert it to xaml. 

    http://www.microsoft.com/products/expression/en/graphic_designer/default.aspx

    Wednesday, February 08, 2006 11:23 AM
  • Although you provide a "work around" method to this issue, it doesn't really answer the question about Metafile (wmf, emf) support.

    Having hundreds of emf vector based images would make this conversion a cumbersom task.

    Question: Lets say I now have the XAML conversion from Graphic expression, how do programmically read (C#) in the XAML file and render it to the canvas?


    Wednesday, February 15, 2006 9:01 PM
  • WPF does not support the EMF and WMF image formats. These formats are more susceptible to security vulnerabilities than other image formats, so we do not intend to support them.

    However, the Windows Imaging Component, which is part of WPF, is extensible. A 3rd party could write a codec for EMF or WMF that's compatible with the Windows Imaging Component. Anyone who installs the codec will be able to display the corresponding image format in any WPF application or any application built on WIC. (Like any image format, if a security vulnerability is found, the codec will be disabled until a patch is released.)

    Monday, March 13, 2006 11:40 PM
  • Hello Peggi,

    By writing such a Windows Imaging Component Codec for EMF format, would it be possible to preserve all vector information, or is the output always a pixel-based format?

    Does such a Codec run as managed code, or do we need to use C++ / unmanaged code?

    Thanks,
    Adrian

    Tuesday, March 14, 2006 8:33 AM
  • If you were to write a Windows Imaging Component codec for the EMF format, the output would be pixel based.

    All codecs written for the Windows Imaging Component are written in unmanaged code. However any Windows Imaging Component codecs installed on the system are accessible through WPF automaitcally (without any extra code) when APIs such as BitmapDecoder, BitmapFrame, BitmapImage are used.

     

    Tuesday, March 28, 2006 7:01 AM
  • Microsoft ought to first check what this .emf ending can do to current XP SP2 security.

    This site:  http://graphic.snupigood.com/

    shows a list of files that if clicked on will begin a sequence of events that will infect your computer with a.bat using the .emf extension.

     

    The full file name is: Microsoft_Windows_Advanced_Upgrade_Wizard_Logo______________________________________________________________________.emfx

    and shows up in local settings under the temporary internet files where it calls svchost.exe and replaces it with its own version.

    So, the .emf file was a convenient way for some hacker and virus writer to skate right around Windows security and the multimillionaire owners of the network hosting snupigood, and his parent porn site, have figured out not only how to hijack your browser, but how to hijack it from falsely advertised link on Google - the billionaire boys who keep getting fatter in San Francisco, but won't fix their stupid network.

    And people wonder how viruses spread.  I checked out the ownership of this site, the site that hosts it, and the massive network run by some freaks from Harvard, Dallas, Israel, former landgrabbers known as GI Partners with lots of fancy degrees and jobes behind their names, but either ignorant as hell, or, part of this pornography and organized crime ring in California.

    esthost and estdomains, using the New York City three country shell game to route from California, to incorporation state Delaware, to UK, to Russia, and then make it look like their scripts come from Russia.  They have also developed the phpBB worm that the phpBB developers keep complaining about, but can't find the authors of; they're in California boys!

    I've had quite enough of these rich bimbos attacking smaller startups, stealing land and money from people, and now, hacking into computers by using script code, which these millionaires know quite well, without being investigated.  Maybe Microsoft ought to look at who is attacking its back from California, yet again!

    What a gang; GI Partners; selling bandwidth paid for by pornography and breaking and entering into unsuspecting internet surfer's computers, with the help of false advertising on Google links.

    And you thought they were script kiddies.  Sorry, PhD's from the financial industry at the NYSE; who else would do anything for money, even prostitution?  Their schools read like a who's who of universities: Harvard, Stanford, Princetion, and Yale.  Guess what, they may not write the viruses, but you can bet they gave the orders to have them written.

    Microsoft, you had better check this out.  And if you want to hire me, I'm available, I could use the reward money for catching these hackers.

     

    Tuesday, March 28, 2006 3:18 PM
  • WPF does not support the EMF and WMF image formats. These formats are more susceptible to security vulnerabilities than other image formats, so we do not intend to support them.

    However, the Windows Imaging Component, which is part of WPF, is extensible. A 3rd party could write a codec for EMF or WMF that's compatible with the Windows Imaging Component. Anyone who installs the codec will be able to display the corresponding image format in any WPF application or any application built on WIC. (Like any image format, if a security vulnerability is found, the codec will be disabled until a patch is released.)


    I know this thread is way out of date, but this DAFT comment about WMF and EMF formats is wrong.  It is the RENDERING ENGINE that isn't secure not the format!!  The format is a Vector Graphic and consists of descriptions of lines, simple filled shapes and Text.  A good rendering engine will only draw the graphic as described, it will protect the system from buffer overruns (a programming error) and any other ____ that may have been put in the file to try and break security.

    Most of the exploits I read about are due to badly written codecs and rendering engines which are allowing deliberately corrupted files to corrupt the system instead of swallowing/ignoring the bad data.  Alternately formats have been "extended" to allow machine interactive functionality which does not belong in a picture/graphic or video file.  The first one of these I encountered was the ANSI driver for DOS which allowed disk access controls to be embedded in display screen text strings!!

    Buffer overruns have plagued DOS and Windows for over 20 years yet the problem and solutions to buffer overruns has been known for well in excess of 30 years (yes they pre-dated PC's).  To allow the possibility of buffer overruns in code is just sloppy programming (yes it saved code space and that was often the excuse in 1986, but in 2010 with 150Mb programs that is just a sorry excuse).

    .GIF is supported in WIC and .GIF over the years has been a common way to compromise windows systems.  Hence the many 1 pixel .GIF images that are 10-50k bytes in size!!! Also the use of 1 pixel GIF as a WEBBUG for tracking which is still current, and this  ONLY works because the browser lets it happen.

    .WMF and .EMF which are the ONLY globaly supported Windows Vector files and the format for nearly ALL Microsoft Clip Art. 

    The .WMF and .EMF exploits were reportedly the result of a Microsoft programmer including an extra "feature" to solve a problem on an earlier Windows 3 system and was accidentally enhanced in its conversion to 32 bit.  This feature is not part of the documented format.  This was fixed in a 2006 patch.  At a similar time and since, several rendering bugs in .PNG, .GIF, .JPEG, .TIFF ... which allowed exploits have been patched.

    The WMF format is TOTALY secure as long as the rendering engine only impliments the vector format required for imaging and doesnt start adding extra commands to reset a printer or etc.

    I have just updated to 64 bit Windows 7 with Office 2010.  I use Coreldraw to generate vector images and embed them in Word documents where they are illustrations (not pictures) and schematics in technical documentation.  I used to use explorer ICONS and "Preview" to choose between the hundreds of drawings to insert.  My productivity has gone down by a significant factor and I must find a solution, unfortunately the only codec I have found only supports 32 bit.

    These are Microsoft formats, surely they should have Microsoft Codecs.

    Friday, August 06, 2010 11:23 PM