#Writing Text onto an existing png image

1 messages · Page 1 of 1 (latest)

solemn dune
#

I am trying to write a sting of text to an image but the image comes out with no text on it, please help

import java.net.URL;
import java.awt.*;
import java.io.*;
import javax.imageio.*;

public class TextWriter{

    public static void main(String[] args) throws Exception {
        final BufferedImage image = ImageIO.read(new File("Maxwell.png"));

        Graphics g = image.getGraphics();
        g.setFont(g.getFont().deriveFont(30f)); // setting font size
        g.drawString("Hello World!", 100, 100);
    

        //g.dispose();

        ImageIO.write(image, "png", new File("test.png"));
    }
}```
dapper crownBOT
#

This post has been reserved for your question.

Hey @solemn dune! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

left onyx
#

have you tried g.drawString(text, xpos, ypos)?

solemn dune
#

yes its in the code on line 14

left onyx
#

oh im being silly

solemn dune
#

Dude I need help not jokes

left onyx
#

???

#

i made a mistake and acknowledged it?

solemn dune
#

Its ight I just need this code to work and have been trying to make it work for the past 5 hours

left onyx
#

what IDE are you using?

#

if its eclipse trying press f5 on the file

solemn dune
#

vscode

left onyx
#

ok nvm

#

is it the final keyword preventing it from being changed? ( i am not that smart)

solemn dune
#

ooh that might be it

#

lemme try

#

Holy crap that was it thank you bro!

#

Man i feel stupid

left onyx
#

wow im surprised, you're welcome

#

happens to the best of us

solemn dune
#

Man I am so happy

left onyx
#

im glad

solemn dune
left onyx
#

if it's solved, you should close the post

solemn dune
#

okie dokie