In the Linux environment, the generated picture with text in the foreground has been shown as box garbled, Windows environment is normal.
Img.setfont (New Font ("Arial", Font.Bold, 20));
You must set the font before you can enter a picture in Chinese, and the font must support Chinese, otherwise it will appear garbled or box, question mark and so on.
BufferedImage in memory created by the image call is the server-side font, so in img.drawstring (str, x, y), if the server can not find the corresponding Chinese font, then it will not be recognized, the last to write a picture of Chinese has become garbled, box, Question mark and so on.
There are two ways to add a server-side Chinese support here:
The first method, add the text body in the system (Arial):
[Email protected]:~# cd/usr/share/fonts
[Email protected]:/usr/share/fonts# mkdir winfonts
[Email protected]:/usr/share/fonts# CP/HOME/DRAGON/DESKTOP/SIMSUN.TTC winfonts
[Email protected]:/usr/share/fonts# cd winfonts
[Email protected]:/usr/share/fonts/winfonts# mkfontdir
[Email protected]:/usr/share/fonts/winfonts# Mkfontscale
The second method, add the JRE Chinese font (Arial):
[Email protected]:~# cd/usr/lib/jvm/java-6-sun/jre/lib/fonts
[Email protected]:/usr/lib/jvm/java-6-sun/jre/lib/fonts# CP/HOME/DRAGON/DESKTOP/SIMSUN.TTC.
You must restart the server to be valid after you modify it.
BufferedImage Graphics DrawString Chinese garbled solution under Linux environment