I need to measure a string width and height in pixels in .NET Core 2.
In .NET Framework can be done using Graphics.MeasureString
method, but in .NET Core, Graphics class no longer exists.
I also tried to find a Font or FontFamily class and extract the font size, font ascent and fond descent, but I couldn't find any or something similar.
With the current .NET Core version, that is still under hard work, it is possible to measure a string or to get the font metrics?
Update 17 November 2017
Windows Compatibility Pack for .NET Core is in preview as of today includes System.Drawing.Common and soon will include System.Drawing package.
It is possible to use CoreCompat.System.Drawing.v2
NuGet package which provides cross platform implementation of System.Drawing assembly based on Mono. I am using it currently on Windows, Linux and macOS in CI runs and so far without major hiccups.
DotNet team has finished already work on porting System.Drawing functionality to .NET Core (see issue #20325 in CoreFX GitHub repo Support Full System.Drawing Functionality on .NET Core and issue #24909 Ship .NET Framework compatibility pack. First preview release is planned for November 2017.
Shipping is planned with .NET Core 2.1.0 version and jointly with .NET Framework Microsoft compatibility pack. Package will support all major platforms with exception of UWP on Windows.
Graphics.MeasureString
function is implemented here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With