2012-08-15 37 views
3

我需要在我的應用程序中獲取矢量形式(點和曲線)中字母的形狀。我可以很容易地獲得Font實例,並且看起來GlyphVector類能夠給我所需的Shape。但要創建從FontGlyphVector,我需要有一些FontRenderContex是否有可能從字體中獲取矢量形式的字符?

我在渲染某些東西時不執行此操作,因此我看不到如何得到那個FontRenderContex。是否可以創建一些默認的FontRenderContex或繞過它?

+1

看起來你可以用'new FontRenderContext(null,false,false)'來創建它。你嘗試過嗎? – 2012-08-15 13:46:11

+0

@Banthar - 是的,似乎我能從中得到一些有趣的東西。謝謝! – Rogach 2012-08-15 13:49:06

回答

1

您的應用程序中是否有任何擴展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. 
+0

嗯。這是有道理的,但究竟是那些結果呢?我的意思是,我可以忍受小的(半像素)不準確,但如果它會導致奇怪的連接點混亂,那不是我想要的。 – Rogach 2012-08-15 13:57:44

+0

我會想象如果這些不準確性很小,他們會在文檔中稍微有點不同。這種措辭讓我覺得結果可能會更糟糕。 – 2012-08-15 14:03:03

1

我不知道,如果這個工程,但你可以得到FontRenderContext從來自BufferedImage對象的Graphics2D對象;

BufferedImage img = new BufferedImage(8, 8, BufferedImage.TYPE_INT_ARGB); 
Graphics2D g2 = img.getGraphics(); 
FontRenderContext frc = g2.getFontRenderContext(); 
相關問題