question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Need to add helpers for validating Graphics rendering

See original GitHub issue

There 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:

  1. 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.
  2. 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:open
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
willibrandoncommented, Dec 30, 2020

I can now inspect the PointData in the EmfPlusDrawLines record. I understand what you mean about the process being slow.

@drawLines->Count.Should().Be(2); // Number of points

MetafilePlusPoint from = @drawLines->GetPoint(0);
MetafilePlusPoint to = @drawLines->GetPoint(1);
from.X.Should().Be(1);
from.Y.Should().Be(1);
to.X.Should().Be(3);
to.Y.Should().Be(5);
1reaction
JeremyKuhnecommented, Dec 22, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tag Helpers in ASP.NET Core
Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files. For example, the built-in ...
Read more >
Built-in Helpers
Helpers are the proposed way to add custom logic to templates. You can write any helper and use it in a sub-expression. For...
Read more >
The Validation Tag Helper in Razor Pages
The validation tag helper targets the HTML span element, and is used to render property-specific validation error messages.
Read more >
Render properties with Tag Helpers
Tag Helpers were introduced in ASP.NET Core as an alternative to HTML helpers for rendering HTML in Razor views. Optimizely Content Management System...
Read more >
Handlebars Helpers Reference
Handlebars Helpers Reference. This article is a reference for Stencil supported Handlebars (opens in a new tab) helpers. It includes custom helpers ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found