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

2020/11/25

Drawing text onto a GreenfootImage

RcCookie RcCookie

2020/11/25

#
I would like to print a text onto a GreenfootImage. This can be done with "new GreenfootImage(String string, int size, Color foreground, Color background, Color outline). However, while this method does give you a handful of options to customize the text size, you cannot edit the font (style, bold, italic...), which I would like to specify. I don't know any other way to print text onto a GreenfootImage, can someone help?
danpost danpost

2020/11/25

#
Only other way is using the drawString method on a pre-existing GreenfootImage object. Unfortunately, unless you use a mono-spaced font, you will not be able to determine the exact image width required for your text.
RcCookie RcCookie

2020/11/25

#
I was just searching through the GreenfootImage source code, I am currently trying to reuse the code they used to create these images. Will have to take a closer look at BufferedImages for that though.
danpost danpost

2020/11/25

#
RcCookie wrote...
I was just searching through the GreenfootImage source code, I am currently trying to reuse the code they used to create these images. Will have to take a closer look at BufferedImages for that though.
Keep in mind that many of the imported classes (including BufferedImage) is part of the java.awt package and will not run on any site in HTML-5 javascript. If that is not a problem, I suggest you check out my TextImage Support Class scenario.
danpost danpost

2020/11/25

#
danpost wrote...
If that is not a problem, I suggest you check out my TextImage Support Class scenario.
It is now updated to run in newer versions of greenfoot.
You need to login to post a reply.