For a Belgian sports community project, built in ASP.Net Core, I am dynamically rendering an image in C#. The image is based on a "base picture", in which I dynamically add Text and then return the image to the client.
It works well, and I am quite happy with the results.
However, when I compare the image that is generated client side, on my dev environment (which is MacOS), that image renders more beautiful, compared to my production environment (a Linux VM in the Azure platform).
As a comparison, you can see two pictures, and you will see the difference, when looking at the texts. The text strings look much more pixelated, in the second picture.
Is there something I can do, to avoid this? Could this be related to the (un)availability of a GPU, or something like that?
Any insights are welcome.
(I also have added the Nuget package runtime.osx.10.10-x64.CoreCompat.System.Drawing to my project, which was needed to run successfully on my MacOS)
For reference: the relevant code snippet:
public async Task<byte[]> CreateImageAsync(YearReview summary)
{
var fonts = new PrivateFontCollection();
fonts.AddFontFile(Path.Combine(_hostingEnvironment.WebRootPath, "fonts/bold.ttf"));
fonts.AddFontFile(Path.Combine(_hostingEnvironment.WebRootPath, "fonts/light.otf"));
var boldFont = fonts.Families[0];
var lightFont = fonts.Families[1];
var assembly = Assembly.GetAssembly(typeof(YearImageGenerator));
var resourceName = "CotacolApp.StaticData.year-a.png";
// Leaving out some variable/constants, irrelevant to the sample
await using (var stream = assembly.GetManifestResourceStream(resourceName))
{
var bitmap = new Bitmap(stream);
using (var gfx = Graphics.FromImage(bitmap))
{
using (Font f = new Font(boldFont, 58, FontStyle.Bold, GraphicsUnit.Pixel))
{
gfx.DrawString($"{summary?.UniqueColsInYear.Number()}", f, Brushes.Black,
new RectangleF(0, startHeightYear, yearValuesRightBorder, 100f), rightAlignFormat);
}
}
using (var imgStream = new MemoryStream())
{
bitmap.Save(imgStream, System.Drawing.Imaging.ImageFormat.Png);
return imgStream.ToArray();
}
}
}
If you compare the pictures, look at the black numbers on the left , and the black text on the right side of the picture.

