Show Multiple BufferedImage in jsp

旧巷老猫 提交于 2019-12-25 02:10:07

问题


I have 100 BufferedImage object's in ArrayList, i want to show all of these images in a jsp.

<%
  ArrayList<BufferedImage> list = GlobalData.getImageBufferArrayList();
%>

 </head>
 <body>
 <ul>
 <li><img alt="" src=""> </li>//image1
 <li><img alt="" src=""> </li>//image2
 <li><img alt="" src=""> </li>//image3
   ...
   ..
   ...
 </ul>
</body>

I don't know what to put in src on these images

Is it possible to put image data as src of image.(Just like we get image data from canvas in html)

Or is their any decent way of showing these images.


回答1:


You either have to embed the image files into the HTML document, or make it available through separate HTTP requests. For the former you can use the data: URI scheme. For the latter, you have to provide a separate servlet, or a separate code path inside that same servlet, which will serve the image file. It might do so from some short-lived cache, so you won't have to execute the same code again to obtain these images.

In general, embedding the data has a size overhead proportional to the size of the image, whereas the separate requests have a resource overhead proportional to the number of HTTP requests. For small images, the former might be better, while for large images the latter will be faster. Implementing the embedding should be easier than implementing a reasonable image cache, but I'm not 100% sure whether all browser support the data scheme.

In either case, you'll have to serialize the BufferedImage to some byte sequence first, probably using ImageIO.write in conjunction with a ByteArrayOutputStream.



来源:https://stackoverflow.com/questions/15510521/show-multiple-bufferedimage-in-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!