I need to draw a string to a BufferedImage in Java. The way this is done doesn't matter, however the image should take up only the space it needs, like in the example below. I need a new BufferedImage created containing only the string. Extra space above the string and on the right side of the string could be tolerated, but I can't have extra space below and left of the drawn string.
Is something like this possible? I have tried to do it myself, but I always end up having extra space which is not what I want. Any help would be appreciated.