Need to add helpers for validating Graphics rendering
See original GitHub issueThere are two components to this. The first is relatively easy- we need helpers and some examples to view GDI calls generated when rendering to a Graphics
object. The second is more complicated- we need to be able to look at GDI+ records.
Recording and playing back GDI records from a Graphics object can be done in a few ways:
- We can create a Graphics object around a Metafile HDC we create and just look at that HDC the way we’re already doing it.
- We can create a System.Drawing MetaFile around a stream and create a Graphics object from that to record to. You can then grab the HENHMETAFILE from the MetaFile and enumerate the way we already are.
Enumerating the GDI+ records is more complicated as the record headers and parsing need to be created from scratch by following the EMF+ specification.
I’ve started fiddling with the lower level APIs with this here: https://github.com/JeremyKuhne/WInterop/blob/main/src/Tests/WInterop.Tests/GdiPlus/Metafiles.cs#L65 This code can be used to find the equivalent System.Drawing entry points.
The EMF+ specification: https://docs.microsoft.com/openspecs/windows_protocols/ms-emfplus/5f92c789-64f2-46b5-9ed4-15a9bb0946c6
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (8 by maintainers)
I can now inspect the PointData in the EmfPlusDrawLines record. I understand what you mean about the process being slow.
@willibrandon Enumerating the top-level records in EMF+ is relatively easy as GDI+ gives you a record enumerator (exposed in
System.Drawing.Imaging.Metafile
). Getting the details out of each record takes a little bit of work to get started as you have to sequentially scan as there aren’t offsets to let you skip to the data you care about. I started playing with this in the WInterop project I linked above (the tests in the link above show how the data presents itself when viewed as a standard EMF or through the EMF+ enumerator). It can be used freely as a base/reference to doing a more complete parser. I intend to keep expanding the implementation there, but I don’t have an expected timeframe.