繁体   English   中英

如何在Web服务器上安装字体以在Web API上的graphics.DrawString方法中使用

[英]How to install fonts on web server to use in graphics.DrawString method on web api

我正在.net中开发一个使用graphics.DrawString在图像上绘制文本的应用程序。 此方法接受字体作为参数,在我的本地计算机上安装字体,并且可以在其中使用它,但是如何在主机上安装字体(在主机上,您无权访问操作系统来安装字体,因此,面板)以我的身份将其作为web app托管在Azure

然后我的问题是我应该如何在Web服务器上安装字体,或者实际上应该仅在该功能中使用它。

        using (Graphics graphics = Graphics.FromImage(bitmap))
        {
            // some codes
            graphics.DrawString(text, font, brush, location, drawFormat);
        }

我发现了解决方案,以防其他人遇到相同的问题:

PrivateFontCollection collection = new PrivateFontCollection();
    // Add the custom font families. 
    // (Alternatively use AddMemoryFont if you have the font in memory, retrieved from a database).
    collection.AddFontFile(@"E:\Downloads\actest.ttf");
    using (var g = Graphics.FromImage(bm))
    {
        // Create a font instance based on one of the font families in the PrivateFontCollection
        Font f = new Font(collection.Families.First(), 16);
        g.DrawString("Hello fonts", f, Brushes.White, 50, 50);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM