Solution to Chinese garbled BufferedImageGraphicsdrawString in Linux

Source: Internet
Author: User
In linux, text images are displayed as garbled boxes at the front-end. windows is normal. Img. setFont (newFont (, Font. BOLD, 20); before entering the image, you must set the font, and the font must support Chinese characters. otherwise, garbled characters, boxes, question marks, and so on will appear. BufferedImage images created in memory call services

In linux, text images are displayed as garbled boxes at the front-end. windows is normal.

Img. setFont (new Font ("", Font. BOLD, 20 ));

Before entering the image, you must set a font that supports Chinese characters. otherwise, garbled characters, boxes, question marks, and so on may occur.

The image created by BufferedImage in the memory calls the server-side font, so in the img. drawString (str, x, y); if the server cannot find the corresponding Chinese font, it cannot recognize it, finally, the Chinese characters written into the image become garbled characters, boxes, question marks, and so on.

There are two ways to add Chinese support for the server:

The first method is to add the system Chinese font ():
Root @ dragon-virtual-machine :~ # Cd/usr/share/fonts
Root @ dragon-virtual-machine:/usr/share/fonts # mkdir winFonts
Root @ dragon-virtual-machine:/usr/share/fonts # cp/home/dragon/Desktop/simsun. ttc winFonts
Root @ dragon-virtual-machine:/usr/share/fonts # cd winFonts
Root @ dragon-virtual-machine:/usr/share/fonts/winFonts # mkfontdir
Root @ dragon-virtual-machine:/usr/share/fonts/winFonts # mkfontscale
Method 2: Add the jre Chinese font ():
Root @ dragon-virtual-machine :~ # Cd/usr/lib/jvm/java-6-sun/jre/lib/fonts
Root @ dragon-virtual-machine:/usr/lib/jvm/java-6-sun/jre/lib/fonts # cp/home/dragon/Desktop/simsun. ttc.

The modification takes effect only after the server is restarted.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.