5

I am currently using Cobra: Java HTML Renderer & Parser to render an HTML page that is dynamically generated based on user choices in a java app.

In my app the user has a choice of hundreds of items to select. The items are displayed in the form of special uniquely colored symbols and the user can select more then one item.

Once a number of items are selected their written description is dynamically generated and formatted to include css2 and html4 tags and loaded into the Cobra HTMLPanel for display.

I wish to display the image of the symbol with the written description of an item in the HTMLPanel.

One way to do this would be to save the BufferedImage to a file using ImageIO.write and then include the img html tag in my dynamically generated HTML document that is being loaded into HTMLPanel. Unfortunately this is unacceptable as there may be hundreds of symbols being selected by the user wich in turn would result in hundreds of ImageIO.write calls and an incredible decrease in performance of my app.

An alternate way would be to convert the BufferedImage to a Base64 encoding and then directly place the encoding into the HTML document as follows

<img alt="Embedded Image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />

Unfortunately HTMLPanel appears to ignore the data URI scheme.

Does anyone know a solution?

Tractatus
  • 51
  • 2
  • But if you display the images in your application, they have to be on file somewhere, right? Why don't you point there? – Jules Feb 07 '11 at 11:39
  • The symbols are numerous and can vary in colour therefore they are also procedurally drawn by the app and are not stored in a file form but only exist in memory. – Tractatus Feb 07 '11 at 18:44

1 Answers1

1

Use an embedded servlet container like Jetty. Point the URLs to "http://localhost:somePort/imageId", and then serve those URLs up from memory.

Jesse Barnum
  • 6,507
  • 6
  • 40
  • 69
  • Unfortunately this approach feels bit to complicated. I looking for a clean and simple way to get this to work. – Tractatus Mar 19 '11 at 19:17