Convert WMF / EMF C # File Format

In my program, I have a requirement for "playing" or "parsing" Windows metafiles (WMF and EMF). I dug through MSDN and Google, and the closest I came to Graphics. EnumerateMetafile Method I can make it work because my EnumerateMetafileProc callback is called, and then I can call PlayRecord. There is no way to extract useful data from this callback.

Example: I looked: http://msdn.microsoft.com/en-us/library/ms142060.aspx

The callback has a recordType parameter, which is ENUM. Well, this looks useful, except that they don't seem to be able to distinguish data from any useful type.

My goal is to reproduce the creation of WMF / EMF so that I can make function calls in a specialized graphic class that has such methods (DrawLine, DrawPoint, DrawArc). In a way, I am re-creating a WMF / EMF drawing in a completely different format (Conversion).

Any help on this is greatly appreciated.

+4
source share
2 answers

Graphics.EnumerateMetafile , unfortunately, is a very thin layer around the Win32 API. For each entry in EMF, you get an unmanaged memory address for a particular entry. There is no documentation about what it might contain, but then there is not much in the Win32 world.

So you need to consult with ancient texts!

This book comes with a sample CD-ROM with sample code that includes sample programs for using the EMF playback API.

This leaves you with two problems.

  • The book obviously goes out of print, so make sure that any used copy you buy includes a working CD.

  • The sample code is everything in C / C ++, and it will be a non-trivial task to declare the necessary interaction for 100 or so structures that are used to describe all EMF records.

So another approach could be to declare a huge interface in .NET that has a method for every GDI call you need to intercept, and then use C ++ / CLI to adapt the C ++ code sample so that it calls your huge interface for each entry.

Update

Although the MSDN documentation for EMF playback does not contain information on specific EMF records, Microsoft has separately published the full specification as of 2006:

MS-EMF: Advanced Metafile Format

Also, the author of the book I linked to above made the source code for the CDROM samples available for download:

Windows Graphic Programming Source Code

+6
source

Check out this library: http://wmf.codeplex.com/

The idea is to scroll through WMF records and transform shapes, brushes, etc. to another format

WmfDocument wmf = new WmfDocument(); wmf.Load(path); foreach (var record in wmf.Records) { if (record is WmfCreateBrushIndirectRecord) { var brush = record as WmfCreateBrushIndirectRecord; Console.WriteLine("Color: " + brush.Color); Console.WriteLine("Style: " + brush.Style); Console.WriteLine("Hatch: " + brush.Hatch); //Do something with brush here... } else if (record is WmfRectangleRecord) { var rectangle = record as WmfRectangleRecord; //Do something with rectangle... } else if ... //Other shapes to be implemented } 
+2
source

Source: https://habr.com/ru/post/894901/


All Articles