2014-04-21 20 views
1

我目前需要獲取角色的真實高度。我知道像getDecsent(),getAscent()等函數,但它們只允許獲取有關孔字體的值(在其上下文中)。我也嘗試過使用getStringBounds()的方式,但這是同樣的故事。如何獲得角色的真實高度(fontmetrics/graphics2d)

就像標題所說,我一直在尋找一種方法來獲得一個字符的高度值。

例如,「N」是高於高「N」,'我只是那麼一點點「我」等

感謝您的時間

+0

歡迎來到SO。你可以通過詳細闡述你的問題來提供幫助。你高度是指像素高度? – bubble

+0

謝謝。是的,我的意思是像素高度。 – Markus

回答

0

使用此

Rectangle2D bounds = font.getStringBounds("put your string here", context); 
//font can be set to whatever you want 
//my suggestion is that you use the same font for both characters 
//context is a object of FontRenderContext 
System.out.println(bounds.getHeight()); 
//Instead of just printing it you could do this a second time and compare the 2 strings 
相關問題