• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Putting text in an image file

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
How can we put some text in an image file using Java?
I have a String and I want to put this String in an image file (.gif, .bmp, .jpg or any other).
Any help would be appreciated.

Thank you.
Ishan
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You certainly can write text into an image in Java, and you can write the result into a file in some popular image formats.

However, if, as posting in the beginner forum suggests, you are new to Java, this might not be a good choice for your first Java program!

You can use javax.imageio.ImageIO class to read and write the image.

To write text into the image, you need to get it as a BufferedImage. Then get a Graphics2D from your BufferedImage. Then you can use Graphics2D.drawString() to write text. You may wish to set the Font and Color of the Graphics2D before writing the text. A FontMetrics object can be used to find out how big the text will be.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree that this may not be the best topic for a beginner to cut his teeth on, but here's Sun's tutorial: http://java.sun.com/docs/books/tutorial/2d/index.html

And here's the Hello World program:

[ February 02, 2006: Message edited by: Jeff Albertson ]
 
Happily living in the valley of the dried frogs with a few tiny ads.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic