0

I have a method which generates images using DrawString(). If I call this method on every machine I tested from any program with an UI or from Console-App every thing is fine. The image shows the right font.

But if I call this method from windows service or from IIS website GDI (?) automatically changes to Microsoft Sans Serif without any exception.

It was working for years on Windows 7. After change to Windows Server 2019 the problem occurs first time. Now I have 2 developer machines with Windows 10 Build 20H2 and the same .NET versions on both. On one machine image generation works well, on the other machine the font changes. Any idea, what I can do, to get it work on every machine?

public void GenerateBitmap()
{
    string drawString = "Sample Text 1234567890";

    using  (Bitmap bmp = new Bitmap(5000, 200, PixelFormat.Format32bppArgb))
    {
        bmp.SetResolution(300, 300);
        using (Graphics grfx = Graphics.FromImage(bmp))
        {
            using (Brush brush = new SolidBrush(Color.Black))
            {
                Font f = new Font("MyFontName", 22F);
                grfx.DrawString(drawString, f, brush, new Point(0, 0));
            }
        }
        bmp.Save("test.png", System.Drawing.Imaging.ImageFormat.Png);
        bmp.Dispose();
    }
}
3
  • Where is the code actually being run: on a client machine, or on a server? Commented Jun 7, 2021 at 23:53
  • - Productiv on a Server 2019: with this problem - Development on client 1 Windows 10: with this problem - Development on client 2 Windows 10: without this problem Commented Jun 8, 2021 at 15:47
  • Solved: link Commented Jun 22, 2021 at 11:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.