• 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

Generating images

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am fairly new to servlets and have written a basic servlet to draw a sort of graph from some data. The servlet returns the necessary html and saves out an image file of the graph as .png format to link to. However, it would be nice to include a logo on the graph that comes from an image file, but I'm unsure how to use the drawImage() method of Graphics2D in this servlet case, where I don't have a Component to refer to. Here's some code...

I hope someone can help with this, it should be simple, but it's got me confused!!!
thanks,
Ben
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Images are a separate HTTP request and therefore have to be returned in a separate Servlet. You can't return the page and image all in one hit.
Basically you have a Servlet that defines that returns a content-type of image/gif or image/jpg etc, you build the image then stuff it down the OutputStream.
I tend to use BufferedImages, the Graphics2D Context and the com.sun.image.codec.jpeg package for converting from Graphics to a jpeg. (the sun package is not recommended and not supported and there are other solutions out there, but I was just messing around)
Dave
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might wont to look at sitraka ServerChart component (http://www.sitraka.com) - this is exactly what they do
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic