• Post Reply Bookmark Topic Watch Topic
  • New Topic

How To Add Text to a JPEG image?  RSS feed

 
Ranch Hand
Posts: 1567
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a good source code example that demonstrates how to embed text into an exisiting JPEG image.
I want to put some copyright information into several hundred JPEG files, but can't find a good reference.
I bought the Java2D API reference, but although it's excellent, this text doesn't appear to have a lot of simple examples to get you understanding the basic stuff first.
I look forward to anyone's reply.
Thanks.
-- Mike
 
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java2D API contains a factory for creating some kind of JPEG decoder and encoder objects.
1) Get an implementation of the JPEGImageDecoder interface with JPEGCodec.createJPEGDecoder(InputStream)
2) Call decodeAsBufferedImage() to get a java.awt.BufferedImage of the image.
3) Use the BufferedImage's getGraphics() or createGraphics() method to get a Graphics object to draw with.
4) Draw the text with the methods provided by the Graphics class, i.e. drawString(String, int, int) or drawString(String, float, float).
 
Mike London
Ranch Hand
Posts: 1567
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
You wouldn't have a quick example program would you? <s>
-- Mike
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, sorry
 
Mike London
Ranch Hand
Posts: 1567
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since I've found no complete examples on the web or here, is the issue that everybody knows how to write text on top a JPEG image or nobody does it?
-- Mike
 
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually... I just had this code lying around... it's a water marking gui done in Swing, using the new ImageIO API...

Here it is, all 720 lines of it... Enjoy!

 
And then we all jump out and yell "surprise! we got you this tiny ad!"
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!