我需要在我的应用程序中获取矢量形式(点和曲线)中字母的形状。我可以很容易地获得Font实例,并且看起来GlyphVector类能够给我所需的Shape。但要创建从FontGlyphVector,我需要有一些FontRenderContex。是否有可能从字体中获取矢量形式的字符?
我在渲染某些东西时不执行此操作,因此我看不到如何得到那个FontRenderContex。是否可以创建一些默认的FontRenderContex或绕过它?
我需要在我的应用程序中获取矢量形式(点和曲线)中字母的形状。我可以很容易地获得Font实例,并且看起来GlyphVector类能够给我所需的Shape。但要创建从FontGlyphVector,我需要有一些FontRenderContex。是否有可能从字体中获取矢量形式的字符?
我在渲染某些东西时不执行此操作,因此我看不到如何得到那个FontRenderContex。是否可以创建一些默认的FontRenderContex或绕过它?
您的应用程序中是否有任何扩展Graphics2D?这样,您可以访问getFontRenderContext
方法。
我的意思是,你可以只使用构造函数中的一个,但我看到这个在文档的FontRenderContext:
Typically, instances of FontRenderContext are obtained from a Graphics2D object.
A FontRenderContext which is directly constructed will most likely not represent
any actual graphics device, and may lead to unexpected or incorrect results.
嗯。这是有道理的,但究竟是那些结果呢?我的意思是,我可以忍受小的(半像素)不准确,但如果它会导致奇怪的连接点混乱,那不是我想要的。 – Rogach 2012-08-15 13:57:44
我会想象如果这些不准确性很小,他们会在文档中稍微有点不同。这种措辞让我觉得结果可能会更糟糕。 – 2012-08-15 14:03:03
我不知道,如果这个工程,但你可以得到FontRenderContext从来自BufferedImage对象的Graphics2D对象;
BufferedImage img = new BufferedImage(8, 8, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = img.getGraphics();
FontRenderContext frc = g2.getFontRenderContext();
看起来你可以用'new FontRenderContext(null,false,false)'来创建它。你尝试过吗? – 2012-08-15 13:46:11
@Banthar - 是的,似乎我能从中得到一些有趣的东西。谢谢! – Rogach 2012-08-15 13:49:06