AB4D Forum
Get Metafile from Image Control - Printable Version

+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: Paste2Xaml and Ab2d.ReaderWmf (https://forum.ab4d.com/forumdisplay.php?fid=7)
+--- Thread: Get Metafile from Image Control (/showthread.php?tid=44)

Get Metafile from Image Control - abody - 06-30-2010

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.


RE: Get Metafile from Image Control - abenedik - 06-30-2010


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.

RE: Get Metafile from Image Control - abody - 07-01-2010

In fact I just want to serialize my Image like GetXaml method do.
Is that passible?

RE: Get Metafile from Image Control - abenedik - 07-01-2010

You can use System.Windows.Markup.XamlWriter class (http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlwriter.aspx).

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.