AB4D Forum
ReaderWmf and Clipboard - 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: ReaderWmf and Clipboard (/showthread.php?tid=43)

ReaderWmf and Clipboard - abody - 06-28-2010


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.

RE: ReaderWmf and Clipboard - abenedik - 06-29-2010


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.

RE: ReaderWmf and Clipboard - abody - 06-29-2010

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


RE: ReaderWmf and Clipboard - abenedik - 06-29-2010


Thank you for sharing the code.