Get Metafile from Image Control
Hi all,

I'm trying to get a metafile that I have transform an Image with
ReaderWmf metafileReader = new ReaderWmf();
Metafile metafileImage = Clipboard.GetData(DataFormats.EnhancedMetafile) as Metafile;
IntPtr hEmf = metafileImage.GetHenhmetafile();
Image myImage = metafileReader.GetGeometryFromHemf(hEmf, GeometrySettings.BasicOptimization);
string xamlStr = metafileReader.GetXaml();

Now I have my image control but I'm stuck to get the content as metafile.
I guess the ReaderWmf is not able to do that?
Do you have a solution because I need to do some transformation on my metafile and serialize it as XAML.


I am sorry but I do not understand your problem.

Why would you need a content of a metafile - you have your drawing objects in myImage. You can change the objects - children of Image.

Could you please clarify your question.
In fact I just want to serialize my Image like GetXaml method do.
Is that passible?
You can use System.Windows.Markup.XamlWriter class (

But the created xaml will not be formatted and you will not be able to export embedded images. In some cases it can also create xaml that is not correct (will produce compiler errors). But you can give it a try.

This class is also used in Paste2Xaml (and ViewerSvg) when you uncheck the "Use Advanced XamlWriter" checkbox in Export dialog.

I am planning to create a separate library that would also have GetXaml method that could create formated xaml from any WPF object (and not only from read objects). The library would also have some other useful WPF 2D tools. But I cannot say when it will be available.

Forum Jump:

Users browsing this thread:
1 Guest(s)