About Java adding text to the picture garbled problem __ garbled problem

Source: Internet
Author: User

By the server to the picture text synthesis, the previous paragraph is good. Server for Linux

This side of the request to use Fangzheng font, decisive garbled, play a slide box.

The most important thing is to troubleshoot the problem. The first thought is because the font name for Chinese characters, the front-end to the server is not garbled. I was sent by post, this should not, and after the backstage, really is not the reason. Search engine for help.

Keywords: "DrawString garbled" a search, there are several posts, locked on the server no font on this clue.

First, a program is written to get the fonts supported by the host.

Import java.awt.GraphicsEnvironment;

public class GetFont {public
	static void Main (string[] args) {
		string[] fontnames= Graphicsenvironment.getlocalgraphicsenvironment ().
		Getavailablefontfamilynames ();
		for (String fontname:fontnames) {
			System.out.println (fontname);
		}
	}
}

Upload to the server compiled to perform a bit, only a few logical fonts, no physical fonts. It should be, and then write a test program to upload to the server first

Import Java.awt.Color;
Import Java.awt.Font;
Import Java.awt.Graphics;
Import Java.awt.Graphics2D;
Import Java.awt.Image;
Import java.awt.RenderingHints;
Import Java.awt.image.BufferedImage;
Import Java.io.File;

Import java.io.IOException;

Import Javax.imageio.ImageIO; public class Testfont {public static void main (string[] args) {bufferedimage bi = new BufferedImage (i, Buffere
		DIMAGE.TYPE_INT_RGB);
		Graphics g = bi.getgraphics ();
		Color color = G.getcolor ();
		SYSTEM.OUT.PRINTLN (color);
		G.fillrect (0, 0, 800, 600);
		((GRAPHICS2D) g). Setrenderinghint (renderinghints.key_antialiasing,renderinghints.value_antialias_on);
		G.setfont (New Font ("Founder Blackbody Simplified", Font.plain, 30));
		G.setcolor (Color.Black);
		g.DrawString ("difficult to meet and difficult to do", 200, 50);
		G.setfont (New Font ("Microsoft Ya Hei", Font.Bold, 30));
		G.setcolor (Color.Black);
		g.DrawString ("difficult to meet and difficult to do", 200, 85);
		G.setfont (New Font ("Founder Big Black Simplified", Font.plain, 30));
		G.setcolor (Color.Black);
		g.DrawString ("difficult to meet and difficult to do", 200, 120);
		G.dispose (); Bi.flusH ();
		New name String fname = "abc";
		try {imageio.write (bi, "JPG", New File ("/" + fname + ". jpg"));
		catch (IOException e) {//TODO auto-generated catch block E.printstacktrace ();
 //Save it in C:/imagesort/targetpic}}


Are founder bold, Microsoft Ya black, founder Big Black. Compiled directly on the server, there is no doubt that the generated picture is still garbled.


Check it out, understand that the JVM support font is under the%java_home%/jvm/lib/font, ftp up. Don't know the path direct echo $JAVA _home look at that.

Note that Windows C:/windows/font folders are installed fonts, can not directly FTP upload, copy out in upload to Linux. This font is only Java support, but there is no need to support Linux as a server, other programs do not have a graphical interface.

Run the test again, this time the print is right


Problem solving

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.