ReaderWmf and Clipboard

I'm trying to get a metafile from clipboard with the ReaderWmf component.
But I don't know how I can do that.

I can get a System.Window.Control.Image with this line:
Image clipboardImage = Clipboard.GetData(DataFormats.MetafilePicture) as Image;
I'm not sure this is a good solution and I don't how to create a stream for Image to the ReaderWmf.

Anyone have an idea.

Currently this is quite complicated. I am already preparing a new version where it will be very easy to read metafile from Clipboard and convert it into WPF objects.

With the current version you can use GetFromHemf or GetGeometryFromHemf methods on ReaderWmf to read metafile from clipboard.

For example:
Viewbox pastedObjects = Ab2d.ReaderWmf.Instance.GetFromHemf(hemf).

The tricky part is to get hemf - the handle to a clipboard object (as IntPtr). You can get the handle with COM interop. - Use GetClipboardData function (defined in user32.dll). Before calling GetClipboardData, you should check if metafile is stored on the clipboard with calling IsClipboardFormatAvailable with CF_ENHMETAFILE parameter and if metafile exist open the clipboard before calling GetClipboardData (don't forget to close the clipboard afterward).

Check the web for samples on using the functions.

Or you can wait a little for the new version of ReaderWmf - it will be available in a week or two.
Thanks for your answer. I have find my way......
Here is the solution like as you sayed.

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();

CreateSymbolFromMetafile(new Point(10,10), myImage);


Thank you for sharing the code.

Forum Jump:

Users browsing this thread:
1 Guest(s)