This site requires JavaScript, please enable it in your browser!
Greenfoot back
Jak
Jak wrote ...

2014/3/3

Width and Height of a String in pixels.

1
2
Pointifix Pointifix

2014/3/4

#
ah ok thats the way you mean it, but where do you get the exact image height? to get the image as height as your text you need to know the text height ;)
danpost danpost

2014/3/4

#
The GreenfootImage methods 'getWidth' and 'getHeight' return the dimensions of the image. The GreenfootImage constructor that is being used creates an image having the line height created using the fontsize given in the current font. Using the GreenfootImage method 'getHeight' of the image returns in pixels an equivalent value of what 'fm.getHeight' should return in points (a point is 1/72 of an inch and the conversion to pixels in dependent on your hardware; so using points would display different on different machines).
davmac davmac

2014/3/4

#
where do you get the exact image height? to get the image as height as your text you need to know the text height ;)
FontMetrics getHeight() method returns the standard height of a line of text. You can subtract the leading (getLeading()) from this if you are only displaying a single line. If you want to be absolutely sure that all of the text is visible, you could use getMaxAscent() + getMaxDescent() instead of getHeight().
You need to login to post a reply.
1
2