分类目录

链接

2017年 6月
 1234
567891011
12131415161718
19202122232425
2627282930  

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > .NET, LINUX > 正文
LINUX上GDI+无法使用字体 font family not found
.NET, LINUX 暂无评论 阅读(1,205)

LINUX上GDI+无法使用字体 font family not found

在CentOS中安装中文字体

作者:唧唧

1、先从你本机 C:\Windows\Fonts 拷贝或者网络上下载你想要安装的字体文件(*.ttf文件)到 /usr/share/fonts/chinese/TrueType 目录下(如果系统中没有此目录,则自行mkdir创建,亦可重命名为自己喜欢的文件夹名)

2、修改字体文件的权限,使root用户以外的用户也可以使用

# cd /usr/share/fonts/chinese/TrueType

# chmod 755 *.ttf

3、建立字体缓存

# mkfontscale (如果提示 mkfontscale: command not found,需自行安装 # yum install mkfontscale )

# mkfontdir

# fc-cache -fv (如果提示 fc-cache: command not found,则需要安装# yum install fontconfig )

4、重启计算机

# reboot

2、安装完毕后,我们在代码中指定要使用的字体

  1. context.Response.ContentType = "image/gif";
  2.             Bitmap basemap = new Bitmap(200, 60);
  3.             Graphics garph1 = Graphics.FromImage(basemap);
  4.  
  5.             garph1.FillRectangle(new SolidBrush(Color.White), 0, 0, 200, 60);
  6.             Font font = new Font("consola.ttf", 48, FontStyle.Bold, GraphicsUnit.Pixel);
  7.  
  8.             Random r = new Random();
  9.             string letters = "ABCDEFGHIJKLMNPQRSTUVWXYZ";
  10.             string letter;
  11.             StringBuilder s = new StringBuilder();
  12.             for (int i = 0; i < 5; i++)
  13.             {
  14.                 letter = letters.Substring(r.Next(0, letters.Length - 1), 1);
  15.                 s.Append(letter);
  16.                 garph1.DrawString(letter, font, new SolidBrush(Color.Black), i * 38, r.Next(0, 15));
  17.  
  18.             }
  19.  
  20.             Pen linePen = new Pen(new SolidBrush(Color.Black), 2);
  21.             for (int x = 0; x < 6; x++)
  22.             {
  23.                 garph1.DrawLine(linePen, new Point(r.Next(0, 199), r.Next(0, 59)), new Point(r.Next(0, 199), r.Next(0, 59)));
  24.             }
  25.  
  26.             basemap.Save(context.Response.OutputStream, ImageFormat.Gif);
  27.             context.Session["CheckCode"] = s.ToString();    //存入Session,用于对比验证
  28.             context.Response.End();

再次访问清晰可见啊

 

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:LINUX上GDI+无法使用字体 font family not found | Bruce's Blog

发表评论

留言无头像?