Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How To Add Text to a JPEG image?

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
You wouldn't have a quick example program would you? <s>
-- Mike
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope, sorry
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic