|
|
|
@ -20,10 +20,10 @@ public class WriteCharactorToPng {
|
|
|
|
|
FontMetrics fm = g.getFontMetrics();
|
|
|
|
|
int x = (image.getWidth() - fm.stringWidth(text)) / 2;
|
|
|
|
|
int y = (image.getHeight() - fm.getHeight()) / 2 + fm.getAscent();
|
|
|
|
|
//防锯齿
|
|
|
|
|
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
|
|
g.drawString(text, x, y);
|
|
|
|
|
g.dispose();
|
|
|
|
|
|
|
|
|
|
ImageIO.write(image, "PNG", new File("c:\\output.png"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|