Linux下Java生成中文图像字体乱码,字体是方块解决办法

是Linux没有相应中文字体的原因。以宋体为例1、查看linux下是否有中文字体 [root@VM-0-8-centos console]# fc-list./usr/share/fonts/dejavu/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique

Linux下Java生成中文图像字体乱码,字体是方块解决办法

是Linux没有相应中文字体的原因。

以宋体为例

1、查看linux下是否有中文字体

[root@VM-0-8-centos console]# fc-list

2、创建存放字体的文件夹

[root@VM-0-8-centos console]# cd /usr/share/fonts/

[root@VM-0-8-centos fonts]# mkdir my_fonts

3、将Windows目录中的字体复制到上面创建的文件夹中

windows中的字体目录C:\Windows\Fonts

4、安装mkfontscale

[root@VM-0-8-centos fonts]# yum install mkfontscale

error: rpmdb: BDB0113 Thread/process 26965/140312765970496 failed: BDB1507 Thread died in Berkeley DB library

error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery

error: cannot open Packages index using db5 -  (-30973)

error: cannot open Packages database in /var/lib/rpm

CRITICAL:yum.main:

Error: rpmdb open failed

和我一样安装报错是查看一下解决办法

Linux-centos使用yum命令提示Error: rpmdb open failed的解决办法

[root@VM-0-8-centos rpm]#   yum install mkfontscale

5、在字体文件中执行mkfontscale

[root@VM-0-8-centos rpm]# cd  /usr/share/fonts/my_fonts

[root@VM-0-8-centos my_fonts]# mkfontscale

6、查看安装的中文字体

[root@VM-0-8-centos my_fonts]# fc-list :lang=zh

/usr/share/fonts/my_fonts/SIMSUN.TTC: SimSun,宋体:style=Regular,常规

/usr/share/fonts/my_fonts/SIMHEI.TTF: SimHei:style=Normal

/usr/share/fonts/my_fonts/SIMSUN.TTC: NSimSun,新宋体:style=Regular,常规

7、扫描字体目录并生成字体信息的缓存

[root@VM-0-8-centos my_fonts]# fc-cache -fv

/usr/share/fonts: caching, new cache contents: 0 fonts, 2 dirs

/usr/share/fonts/dejavu: caching, new cache contents: 9 fonts, 0 dirs

/usr/share/fonts/my_fonts: caching, new cache contents: 3 fonts, 0 dirs

/usr/share/X11/fonts/Type1: skipping, no such directory

/usr/share/X11/fonts/TTF: skipping, no such directory

/usr/local/share/fonts: skipping, no such directory

/root/.local/share/fonts: skipping, no such directory

/root/.fonts: skipping, no such directory

/usr/share/fonts/dejavu: skipping, looped directory detected

/usr/share/fonts/my_fonts: skipping, looped directory detected

/usr/lib/fontconfig/cache: cleaning cache directory

/root/.cache/fontconfig: not cleaning non-existent cache directory

/root/.fontconfig: not cleaning non-existent cache directory

/usr/bin/fc-cache-64: succeeded

8、重启java项目就可以了

温馨提醒

如果还不行,可以将Windows中的字体文件复制到jdk中的字体目录试试。

jdk字体目录${JAVA_HOME}/jre/lib/fonts

上一篇 2022年03月27 21:41
下一篇 2022年03月27 22:11

相关推荐

  • 清明节是个怎样的节日,你认为清明节是个怎样的节日

    眼睛一闭一睁,转眼间就到了清明假期的最后一天。假日苦短,只有三天,可是你知道吗,古代的寒食节、清明节、上巳节融合起来,才有了今天的清明节。关于清明节的历史,你了解多少?一起来看看吧!寒食节起源于春秋时

    2023年01月05 205
  • 怎样的节日,一个节日对吗

    火红的灯笼,飘扬的五星红旗,深秋暖阳下,湘西州花垣县十八洞村精准坪广场上,游人如织,这里伫立的“精准扶贫”石碑在阳光下显得格外耀眼。11月2日上午9点,十八洞村精准坪志愿者施芳丽正在有序收拾演出物品,

    2023年01月05 254
  • 怎样画传统节日绘画,画一幅节日画

    冬至又叫冬节、贺冬节,还有亚岁、肥冬、喜冬等称谓,是我国最早制定出的节气。据《左传》记载,现在保留下来的我国对冬至最早的观测记录,是在春秋时代鲁僖公五年(公元前655年)正月辛亥和鲁昭公二十年(公元前

    2023年01月07 217
  • 农历7月15日中元节的传说由来

    由于慧娘还阳的这天是农历7月15日,因此每逢这一天,人们都会给祖先焚香烧纸。这个习俗一直流传至今。

    2023年01月07 0
  • 三月初三上巳节的由来与传说

    三月三,又称“上巳(sì)节”,是一个纪念黄帝的节日,也是中国最浪漫最富有诗意的日子。上巳节也叫春浴日、女儿节,堪称中国最古老的情人节。

    2023年01月07 0
  • 社日节是农历几月几日,社日节(古老的中国传统节日)

    古代把土地神和祭祀土地耕的地方才叫“社”。社日,是古代祭祀土神的日子,所以叫社日节。社日分为春社和秋社,“春社”是按立春后的第五个戊日推算,一般是在农历的二月初二。“秋社”是在立秋后第五个戊日,一般是在新谷登场的农历八月。

    2023年01月09 0
关注微信