I just need to know how I can load a font file and get the characters in an array of data and then call one particular character.
var families = Fonts.GetFontFamilies(@"C:\WINDOWS\Fonts\Arial.TTF");
foreach (FontFamily family in families)
{
}
I just need to know how I can load a font file and get the characters in an array of data and then call one particular character.
var families = Fonts.GetFontFamilies(@"C:\WINDOWS\Fonts\Arial.TTF");
foreach (FontFamily family in families)
{
}
Hopefully this will give you the idea (untested). Take care to use using
or explicitly dispose your graphics objects:
using System.Drawing;
using System.Drawing.Imaging;
...
// Create your bitmap - 100x100 pixels for example
using (Bitmap b = new Bitmap(100, 100))
{
using (Graphics g = Graphics.FromImage(b))
{
g.Clear(Color.White); // White background
using (FontFamily fontFamily = new FontFamily("Arial"))
{
using (Font font = new Font(fontFamily, 24, FontStyle.Regular, GraphicsUnit.Pixel))
{
using (SolidBrush solidBrush = new SolidBrush(Color.Red)) // Red text
{
g.DrawString("A", font, solidBrush, new PointF(10, 10)); // Draw an "A" at position 10,10
}
}
}
}
b.Save(Response.OutputStream, ImageFormat.Jpeg); // return to response, for example
}
}