Using custom TTF font for DrawString image rendering

前端 未结 2 1501
一个人的身影
一个人的身影 2021-02-01 19:36

I am using GDI+ on the server-side to create an image which is streamed to the user\'s browser. None of the standard fonts fit my requirements and so I want to load a TrueType f

2条回答
  •  梦谈多话
    2021-02-01 20:14

    I've found a solution to using custom fonts.

    // 'PrivateFontCollection' is in the 'System.Drawing.Text' namespace
    var foo = new PrivateFontCollection();
    // Provide the path to the font on the filesystem
    foo.AddFontFile("...");
    
    var myCustomFont = new Font((FontFamily)foo.Families[0], 36f);
    

    Now myCustomFont can be used with the Graphics.DrawString method as intended.

提交回复
热议问题