创建一个从Java中字体对象Shape对象 [英] Create a Shape Object from Font Object in Java
问题描述
我有一个字体对象和一个字符串。我想返回一个Shape对象,它是字符串的重新presentation。我有一大堆其他类将显示String和照顾它的。
I have a font object and a String. I want to return a Shape Object that is a representation of the String. I have a whole bunch of other classes that will display the String and take care of it.
我有麻烦搞清楚如何做到这一点时,我的不的有一个图形/ Graphics2D对象。任何帮助吗?我已经搜查了网,但很难找到有用的链接。
I'm having trouble figuring out how to do this when I do not have a graphics/graphics2d object. Any Help? I have searched the net but had trouble finding helpful links.
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;
}
}
感谢
推荐答案
您可以使用的 的GlyphVector#getOutline()
,提到的此处。您可以创建一个的BufferedImage
,为的 在Java SE平台<使用无头模式/ em>的。
You can use GlyphVector#getOutline()
, as mentioned here. You can create a graphics context in a BufferedImage
, as discussed in Using Headless Mode in the Java SE Platform.
又见这些吸引人的例子:
See also these appealing examples:
-
PictureText
,由于的安德鲁·汤普森。
测试
,由于的 SAVVAS Dalkitsis 。
这篇关于创建一个从Java中字体对象Shape对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!