0

Ok.. i'm making a project on Image processing on Java and uptill now i've comnpleted almost all the filters that has to do with RGB filtering. (b/w, sepia, etc) But now i want to add text to image where we get to select the string/jlabel we want to put in the image via a dialog box or a pop up textarea..(what i mean to say is that the text will be decided by the user)

The Program accepts Pixelimage and returns pixel image too.. Now i'm quite new to image so plz it wud be vry helpfull if some1 can assist me with this..

user3291928
  • 85
  • 1
  • 2
  • 8
  • BetterYou search Stackoverflow and check if question is not repeated – Ashish Feb 10 '14 at 07:54
  • possible duplicate of [How to add text to an image in java?](http://stackoverflow.com/questions/10929524/how-to-add-text-to-an-image-in-java) – Ashish Feb 10 '14 at 07:55

1 Answers1

0

Your Question is already answered in SO Click Here answered by dacwe

public static void main(String[] args) throws Exception {
    final BufferedImage image = ImageIO.read(new URL(
        "http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png"));

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

    ImageIO.write(image, "png", new File("test.png"));
}

make use of graphic Option

Output enter image description here

Community
  • 1
  • 1
Ashish
  • 1,856
  • 18
  • 30
  • I have seen this earlier question before but what i'm asking is that we get to select the text after the program has been run.. The text and the position of the text is not predetermined – user3291928 Feb 10 '14 at 07:57
  • Then just change `g.drawString("Hello World!", 100, 100);` to use whatever values you want. – takendarkk Feb 10 '14 at 07:59
  • yes i do get that but a bit confused about the part where the value of "Hello world" and the position (the text and the text position) will be determined by the user AFTER the program has been run, NOT before it.. I mean the user gets to select the text and position according to his/her will when the program is already running – user3291928 Feb 10 '14 at 08:02
  • Take inputs from users and store in variable and then you just place that variables in `g.drawString("Hello World!", 100, 100);` say `g.drawstring('+var1+',var2,var3)` like that.. just take inputs from user and show – Ashish Feb 10 '14 at 13:25
  • Try it once, if you have any issue then paste your code which you have tried in your question then we can help you better. If above answer was helpful consider accepting it by checking "right" symbol aside my aswer – Ashish Feb 10 '14 at 13:37