如何在java中更改图像上文本的字体样式?

时间:2013-05-23 06:35:31

标签: java image bufferedimage

我正在动态创建图像并在图像上书写,字体样式集有限。我想将其更改为"Kunstler Script"中的其他样式。 这是我的代码:

BufferedImage image = new BufferedImage(imageWidth, 
                                 imageHeight,BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    g2.clearRect(0, 0, imageWidth, imageHeight);
    g2.drawImage(image, 0, 0, null);
    g2.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 65));
    g2.setColor(Color.orange);
    g2.drawString(" MY IMAGE", 350, 70);
    g2.drawLine(350, 80, 1000, 80);
    g2.dispose();
    File out = new File("E:/" + IMAGE + "_1.png");
    ImageIO.write(image, "png", out);

这里我要更改字体样式

        g2.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 65));

"SANS_SERIF"的地方我想要一些其他字体,例如"Kunstler Script" 请任何人帮我修补它。 谢谢。

1 个答案:

答案 0 :(得分:1)

假设Kuntsler Script是一种可用的字体,它就像:

一样简单

g2.setFont(new Font("Kunstler Script", Font.BOLD, 65));