when generate a image for chinese character, if your computer has no song ti font style, should read a system file to load the font style.
find following file.
c:\windows\fonts\simsun.ttc
coding as follows:
font ttffont = font.createfont(font.truetype_font, new file("c:\windows\fonts\simsun.ttc"));
font ttfreal = ttffont.derivefont(font.plain, 12);
image = new bufferedimage(width, height, bufferedimage.type_int_rgb);
graphics2d g2 = (graphics2d) image.getgraphics();
g2.setbackground(color.yellow);
g2.clearrect(0, 0, width, height);
g2.setpaint(color.black);
fontrendercontext context = g2.getfontrendercontext();
rectangle2d bounds = ttfreal.getstringbounds(name, context);
double x = (width - bounds.getwidth()) / 2;
double y = (height - bounds.getheight()) / 2;
double ascent = -bounds.gety();
double basey = y + ascent;
g2.setfont(ttfreal);
g2.drawstring(name, (int) x, (int) basey);
find following file.
c:\windows\fonts\simsun.ttc
coding as follows:
font ttffont = font.createfont(font.truetype_font, new file("c:\windows\fonts\simsun.ttc"));
font ttfreal = ttffont.derivefont(font.plain, 12);
image = new bufferedimage(width, height, bufferedimage.type_int_rgb);
graphics2d g2 = (graphics2d) image.getgraphics();
g2.setbackground(color.yellow);
g2.clearrect(0, 0, width, height);
g2.setpaint(color.black);
fontrendercontext context = g2.getfontrendercontext();
rectangle2d bounds = ttfreal.getstringbounds(name, context);
double x = (width - bounds.getwidth()) / 2;
double y = (height - bounds.getheight()) / 2;
double ascent = -bounds.gety();
double basey = y + ascent;
g2.setfont(ttfreal);
g2.drawstring(name, (int) x, (int) basey);