How To Add Text to a JPEG image?
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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).
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).
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Mike London
Bartender
Posts: 1973
17
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks.
You wouldn't have a quick example program would you? <s>
-- Mike
You wouldn't have a quick example program would you? <s>
-- Mike
Lasse Koskela
author
Posts: 11962
5
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Nope, sorry 

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Mike London
Bartender
Posts: 1973
17
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
-- Mike
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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!
Here it is, all 720 lines of it...
Enjoy!-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
| Sometimes you feel like a nut. Sometimes you feel like a tiny ad. The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |







