I've got a method that's supposed to add some text to screenshots. The screenshot is fed into this method as a File object like this:
private void modifyScreenshot(File file) throws Exception {
String textToAdd = "Something something";
BufferedImage image = ImageIO.read(file);
Graphics g = image.getGraphics();
At this point, adding the text via g.drawString is easy to do. However, I want the text to not cover any of the actual screenshot, but be in a white area "above" the screenshot.
What I mean is, at this point, this is what the Graphics object looks like when it gets saved to file:
However, I want it to look like this instead, with the "Some text some text" being the string I specify in the code.
So, how would I be able to add white rectangle above the image where the text can be written?
EDIT: Note, this is not simply adding a string to an image. This involves "enlarging" the canvas to have white space for the string, so that the string is not over the actual image.
Here's the rough idea: