This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Display images and text  RSS feed

 
Adnan Badar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I have to display jpg files placed in some real path(not in web context). Along with images i also have to display header and footer text. I am unable to display both images and text together. I am using this code:
public void doGet() {
response.setContentType("text/html");
File f = new File("D:\\ImageArchive\\file1.jpg");
com.sun.image.codec.jpeg.JPEGImageDecoder decoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(new FileInputStream(f));
java.awt.image.BufferedImage image =decoder.decodeAsBufferedImage() ;

javax.servlet.ServletOutputStream sos = response.getOutputStream();
com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);
}
Thanks in advance....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see anywhere in your code where you actually write to the response, but in any case, no, you cannot mix images and text.
What you CAN do, is to generated HTML with text and image tags that reference the image. To serve images that cannot be addressed via URL, I'd write a servlet that can read and serve the image (and only the image) and reference that in the src attribute of your image tags.
hth,
bear
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!