Load font and get the characters in C#

萝らか妹 提交于 2019-12-14 03:56:34

问题


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)
 {

 }

回答1:


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
        }
    }


来源:https://stackoverflow.com/questions/21290322/load-font-and-get-the-characters-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!