我有一个字体对象和一个字符串。我想返回一个Shape对象,它是String的表示形式。我有一大堆其他类将显示String并处理它。
当不拥有graphics / graphics2d对象时,我无法弄清楚如何执行此操作。任何帮助?我在网上搜索但很难找到有用的链接。
public class SpecializationOfTester extends ParentTester {
private String str;
private Font font;
public SpecializationOfTester(String str, Font font) {
this.font = font;
this.str = str;
}
public Shape getShape()
{
Shape s;
//
//
return s;
}
}
由于
答案 0 :(得分:6)
您可以使用GlyphVector#getOutline()
,如上所述here。您可以在BufferedImage
中创建图形上下文,如Using Headless Mode in the Java SE Platform中所述。
另见这些吸引人的例子: