Reputation: 19843
I am developing an application in .net
that uses graphics.DrawString
to draw text on images. this method accepts fonts as parameter, on my local I install fonts and I can use it there, but how can I install fonts on my host, (on hosting you don't have access to operating system to install fonts, you just have a panel) in my case I host it on Azure
as a web app
.
Then my question is how should I install fonts on web server, or maybe virtually to just use it in that function.
using (Graphics graphics = Graphics.FromImage(bitmap))
{
// some codes
graphics.DrawString(text, font, brush, location, drawFormat);
}
Upvotes: 0
Views: 369
Reputation: 19843
I found solution in case other people having same issue:
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);
}
Upvotes: 1