如何使用Java Graphics.DrawString绘制Wingding.ttf字体的char?

时间:2012-05-11 09:54:39

标签: java graphics drawstring non-unicode

我正在尝试使用Java Graphics.DrawString从Wingding.ttf字体中绘制字符。但结果图像只包含矩形而不是char。

BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR);

Graphics graphics = image.getGraphics();

Font font = new Font("Wingdings", Font.PLAIN, 20);
graphics.setFont(font);

graphics.setColor(Color.BLACK);

graphics.drawString("\u00d8", 10, 10); // THREE-D TOP-LIGHTED RIGHTWARDS ARROWHEAD char

ImageIO.write(image, "PNG", new File(TEST_DATA_DIR + "bullet_char.png"));

我该怎么做?

2 个答案:

答案 0 :(得分:1)

我不认为wingdings是“标准”字体之一

Font font = null;
try {
    font=Font.createFont( Font.TRUETYPE_FONT,
        new FileInputStream(new File("/pathto/WINGDINGS.TTF")) );
} catch(Exception e) {
    System.out.println(e);
}
font=font.deriveFont(Font.PLAIN, 200);
graphics.setFont(font);

一旦你加载了字体(它总是PLANE 1 pnt)你就可以得到你想要的样式和大小....

答案 1 :(得分:0)

由于此处已回答类似问题:Drawing exotic fonts in a java applet,您需要传递\uF0d8而不是\u00d8

graphics.drawString("\uF0d8", 10, 10);