Server environment variations can cause graphics inconsistencies when measuring text dimensions using different fonts. Text that displays correctly on Windows may get truncated on Linux or on iOS or Android, requiring time-consuming fixes.
Wisej.NET 3.5 uses System.Drawing.Common to load fonts and measure the text of controls using the AutoSize property, leveraging GDI+ on Windows and LibGDIPlus on Linux. While on iOS and Android it used ImageSharp wrapped in an early internal version of System.Drawing.Managed because LibGDIPlus is not available for either system.
However, Microsoft deprecated System.Drawing.Common on Linux since .NET 7, and mono (also Microsoft now) has dropped any support for LibGDIPlus on Linux a few years ago. And unfortunately .NET any version doesn’t provide any font or graphic support on iOS and Android.
Where System.Drawing.Common Falls Short
LibGDIPlus is abandoned, needs to be installed on different linux distros and is not easy to find anymore, and it has not been updated in years.
Microsoft has deprecated System.Drawing.Common for cross-platform use starting with .NET 6 and marked it as Windows-only in .NET 7.
Font loading, availability, and measurements may be different from GDI+ on Windows.
Wisej.NET 4 introduces System.Drawing.Managed. A complete, fully managed, self-contained, full replacement for System.Drawing and System.Drawing.Common. It’s entirely written in C#, uses the same namespace as System.Drawing, and provides more than 90% of the same functionality. Internally it is based on the modern ImageSharp library. In fact the project is a direct and ongoing collaboration with James Jackson-South (the lead developer at ImageSharp).
Using System.Drawing.Managed allows Wisej.NET 4 applications to use the same font measurements on Windows, Linux, iOS, Android and MacOS. Additionally, James developed new measuring code designed to achieve the same metrics as Chrome, Edge, and Firefox. The result is that .NET Core applications with Wisej.NET 4 don’t use GDI+ and don’t use LibGDIPlus on any platform, and user code (your applications) that may use any graphic-related code to manipulate images or paint custom controls use the new library without any change.
This example demonstrates:
Same familiar API
Consistent text measurements across all platforms
No platform-specific dependencies required: works identically on Windows, Linux, macOS, and hybrid scenarios
// Using `System.Drawing.Managed` for consistent cross-platform font metrics
using System.Drawing;
// Create an image - Same API, now with consistent results across platforms
using (var bitmap = new Bitmap(200, 50))
using (var graphics = Graphics.FromImage(bitmap))
{
// Configure for consistent rendering
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
// Measure text - will return identical dimensions on any platform
string text = "Wisej.NET 4";
using (var font = new Font("Arial", 12))
{
SizeF size = graphics.MeasureString(text, font);
// Draw text centered in the bitmap
graphics.DrawString(text, font, Brushes.Navy,
(bitmap.Width - size.Width) / 2,
(bitmap.Height - size.Height) / 2);
}
// Use the image in a Wisej.NET control
pictureBox1.Image = bitmap;
}
Autosized controls (i.e. Labels, Buttons) may get resized depending on the font. If your application creates images and draws texts, there may be some minor differences with older fonts and antialiasing.
Migrating to Wisej.NET 4? Please consider:
Windows Deployment: Both .NET Framework and .NET Core targets work seamlessly
Linux Deployment: Deploy with the net8.0 target. It’s fully managed, eliminating LibGDIPlus dependencies.
Hybrid Apps: For iOS, Android, or macOS deployment, deploy with the appropriate target as outlined in the managed graphics documentation.