I have a service that's designed to do image processing. One of the tasks is to overlay a string on an image which is then sent to a program and displayed.
I'm having trouble overlaying the text on a Bitmap image, can anybody help please?
I'm attempting to use:
PrivateFontCollection fonts = new PrivateFontCollection();
public static FontFamily LoadFontFamily(string fileName, out PrivateFontCollection fontCollection)
{
fontCollection = new PrivateFontCollection();
fontCollection.AddFontFile(HostingEnvironment.ApplicationPhysicalPath + '/' + fileName);
return fontCollection.Families[0];
}
FontFamily family = LoadFontFamily("arial.ttf", out fonts);
Font font = new Font(family, 20);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawString("text", font, new SolidBrush(GetColorFromHexString(foreground)), new PointF(10F, 10F));
}
As per the information on this page.
As the service is unaware of what 'Arial' is - it's obviously failing. I've included the .ttf font as a resource in the service with the build content set to 'copy always'.
Thanks!