This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

How To Add Text to a JPEG image?  RSS feed

 
Ranch Hand
Posts: 1611
13
  • 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
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: 1611
13
  • 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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, sorry
 
Mike London
Ranch Hand
Posts: 1611
13
  • 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!

 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!